From 94526df1b1fa842395ec76e2b8db3079e826348e Mon Sep 17 00:00:00 2001 From: ZephOne Date: Wed, 8 Jan 2025 16:13:30 +0100 Subject: [PATCH 1/7] Add cpanm option --with-recommands Fix #9554 --- .../fragments/9554-add-cpanm-option_with-recommands.yml | 2 ++ plugins/modules/cpanm.py | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 changelogs/fragments/9554-add-cpanm-option_with-recommands.yml diff --git a/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml b/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml new file mode 100644 index 00000000000..baa05ae207f --- /dev/null +++ b/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml @@ -0,0 +1,2 @@ +minor_changes: + - cpanm - enable usage of option --with-recommands (https://github.com/ansible-collections/community.general/issues/9554). diff --git a/plugins/modules/cpanm.py b/plugins/modules/cpanm.py index 3f708581acd..be52d7f1dd3 100644 --- a/plugins/modules/cpanm.py +++ b/plugins/modules/cpanm.py @@ -56,6 +56,12 @@ - Only install dependencies. type: bool default: false + withrecommands: + description: + - Installs dependencies declared as recommends per META spec. + - When these dependencies fail to install, cpanm continues the installation, since they're just recommendation/suggestion. + type: bool + default: false version: description: - Version specification for the perl module. When O(mode) is V(new), C(cpanm) version operators are accepted. @@ -167,6 +173,7 @@ class CPANMinus(ModuleHelper): mirror=dict(type='str'), mirror_only=dict(type='bool', default=False), installdeps=dict(type='bool', default=False), + withrecommands=dict(type='bool', default=False), executable=dict(type='path'), mode=dict(type='str', default='new', choices=['compatibility', 'new']), name_check=dict(type='str') @@ -181,6 +188,7 @@ class CPANMinus(ModuleHelper): mirror=cmd_runner_fmt.as_opt_val('--mirror'), mirror_only=cmd_runner_fmt.as_bool("--mirror-only"), installdeps=cmd_runner_fmt.as_bool("--installdeps"), + withrecommands=cmd_runner_fmt.as_bool("--with-recommands"), pkg_spec=cmd_runner_fmt.as_list(), cpanm_version=cmd_runner_fmt.as_fixed("--version"), ) From 0b4ccb445672779afeb158dfbc89cc788675da66 Mon Sep 17 00:00:00 2001 From: ZephOne Date: Wed, 8 Jan 2025 21:49:39 +0100 Subject: [PATCH 2/7] With accepted suggestions --- changelogs/fragments/9554-add-cpanm-option_with-recommands.yml | 2 +- plugins/modules/cpanm.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml b/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml index baa05ae207f..34dbfa2df72 100644 --- a/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml +++ b/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml @@ -1,2 +1,2 @@ minor_changes: - - cpanm - enable usage of option --with-recommands (https://github.com/ansible-collections/community.general/issues/9554). + - cpanm - enable usage of option ``--with-recommands`` (https://github.com/ansible-collections/community.general/issues/9554, https://github.com/ansible-collections/community.general/pull/9555). diff --git a/plugins/modules/cpanm.py b/plugins/modules/cpanm.py index be52d7f1dd3..35f53100351 100644 --- a/plugins/modules/cpanm.py +++ b/plugins/modules/cpanm.py @@ -59,9 +59,10 @@ withrecommands: description: - Installs dependencies declared as recommends per META spec. - - When these dependencies fail to install, cpanm continues the installation, since they're just recommendation/suggestion. + - When these dependencies fail to install, cpanm continues the installation, since they are just recommendation. type: bool default: false + version_added: 10.3.0 version: description: - Version specification for the perl module. When O(mode) is V(new), C(cpanm) version operators are accepted. From 1349fd99ceba9fe882b1df3387782e2a93ccab26 Mon Sep 17 00:00:00 2001 From: ZephOne Date: Fri, 10 Jan 2025 14:22:04 +0100 Subject: [PATCH 3/7] Use install_recommendations for cpanm option --with-recommends --- .../9554-add-cpanm-option_with-recommands.yml | 1 + plugins/modules/cpanm.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml b/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml index 34dbfa2df72..13a9919424c 100644 --- a/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml +++ b/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml @@ -1,2 +1,3 @@ minor_changes: - cpanm - enable usage of option ``--with-recommands`` (https://github.com/ansible-collections/community.general/issues/9554, https://github.com/ansible-collections/community.general/pull/9555). + - cpanm - enable usage of option ``--with-suggests`` (https://github.com/ansible-collections/community.general/issues/9554, https://github.com/ansible-collections/community.general/pull/9555). diff --git a/plugins/modules/cpanm.py b/plugins/modules/cpanm.py index 35f53100351..5a3110ba60c 100644 --- a/plugins/modules/cpanm.py +++ b/plugins/modules/cpanm.py @@ -56,12 +56,17 @@ - Only install dependencies. type: bool default: false - withrecommands: + install_recommendations: description: - Installs dependencies declared as recommends per META spec. - When these dependencies fail to install, cpanm continues the installation, since they are just recommendation. type: bool - default: false + version_added: 10.3.0 + install_suggestions: + description: + - Installs dependencies declared as suggested per META spec. + - When these dependencies fail to install, cpanm continues the installation, since they are just suggestion. + type: bool version_added: 10.3.0 version: description: @@ -174,7 +179,8 @@ class CPANMinus(ModuleHelper): mirror=dict(type='str'), mirror_only=dict(type='bool', default=False), installdeps=dict(type='bool', default=False), - withrecommands=dict(type='bool', default=False), + install_recommendations=dict(type='bool'), + install_suggestions=dict(type='bool'), executable=dict(type='path'), mode=dict(type='str', default='new', choices=['compatibility', 'new']), name_check=dict(type='str') @@ -189,7 +195,8 @@ class CPANMinus(ModuleHelper): mirror=cmd_runner_fmt.as_opt_val('--mirror'), mirror_only=cmd_runner_fmt.as_bool("--mirror-only"), installdeps=cmd_runner_fmt.as_bool("--installdeps"), - withrecommands=cmd_runner_fmt.as_bool("--with-recommands"), + install_recommendations=cmd_runner_fmt.as_bool("--with-recommends", "--without-recommends", ignore_none=True), + install_suggestions=cmd_runner_fmt.as_bool("--with-suggests", "--without-suggests", ignore_none=True), pkg_spec=cmd_runner_fmt.as_list(), cpanm_version=cmd_runner_fmt.as_fixed("--version"), ) From 64fddeef96b6b1e83d73e83316a08af124c848e5 Mon Sep 17 00:00:00 2001 From: ZephOne Date: Fri, 10 Jan 2025 14:25:18 +0100 Subject: [PATCH 4/7] Fix typo in changelogs/fragments/9554 recommands -> recommends --- ...=> 9554-add-cpanm-option_with-recommends-and-suggests.yml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename changelogs/fragments/{9554-add-cpanm-option_with-recommands.yml => 9554-add-cpanm-option_with-recommends-and-suggests.yml} (52%) diff --git a/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml b/changelogs/fragments/9554-add-cpanm-option_with-recommends-and-suggests.yml similarity index 52% rename from changelogs/fragments/9554-add-cpanm-option_with-recommands.yml rename to changelogs/fragments/9554-add-cpanm-option_with-recommends-and-suggests.yml index 13a9919424c..5cdaf24e9e3 100644 --- a/changelogs/fragments/9554-add-cpanm-option_with-recommands.yml +++ b/changelogs/fragments/9554-add-cpanm-option_with-recommends-and-suggests.yml @@ -1,3 +1,3 @@ minor_changes: - - cpanm - enable usage of option ``--with-recommands`` (https://github.com/ansible-collections/community.general/issues/9554, https://github.com/ansible-collections/community.general/pull/9555). - - cpanm - enable usage of option ``--with-suggests`` (https://github.com/ansible-collections/community.general/issues/9554, https://github.com/ansible-collections/community.general/pull/9555). + - cpanm - enable usage of option ``--with-recommends`` (https://github.com/ansible-collections/community.general/issues/9554, https://github.com/ansible-collections/community.general/pull/9555). + - cpanm - enable usage of option ``--with-suggests`` (https://github.com/ansible-collections/community.general/pull/9555). From 56d37fc8236cbed88be721031a6b536205d0d652 Mon Sep 17 00:00:00 2001 From: ZephOne Date: Sat, 11 Jan 2025 21:00:27 +0100 Subject: [PATCH 5/7] Doc for options users have for recommands and suggests dependencies --- plugins/modules/cpanm.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/cpanm.py b/plugins/modules/cpanm.py index 5a3110ba60c..02f4d496532 100644 --- a/plugins/modules/cpanm.py +++ b/plugins/modules/cpanm.py @@ -58,13 +58,17 @@ default: false install_recommendations: description: - - Installs dependencies declared as recommends per META spec. + - If V(true), installs dependencies declared as recommends per META spec. + - If V(false), it ensures the dependencies declared as recommends are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT). + - If parameter is not set, C(cpanm) will use its existing defaults. - When these dependencies fail to install, cpanm continues the installation, since they are just recommendation. type: bool version_added: 10.3.0 install_suggestions: description: - - Installs dependencies declared as suggested per META spec. + - If V(true), installs dependencies declared as suggests per META spec. + - If V(false), it ensures the dependencies declared as suggests are not installed, overriding any decision made earlier in E(PERL_CPANM_OPT). + - If parameter is not set, C(cpanm) will use its existing defaults. - When these dependencies fail to install, cpanm continues the installation, since they are just suggestion. type: bool version_added: 10.3.0 From 24ed756b4b8d6f507b12a056f9b5421202363eb4 Mon Sep 17 00:00:00 2001 From: ZephOne Date: Sat, 11 Jan 2025 21:07:21 +0100 Subject: [PATCH 6/7] Add new args to the command runner. --- plugins/modules/cpanm.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/modules/cpanm.py b/plugins/modules/cpanm.py index 02f4d496532..356cbbb215b 100644 --- a/plugins/modules/cpanm.py +++ b/plugins/modules/cpanm.py @@ -274,7 +274,16 @@ def process(rc, out, err): return pkg_spec = self.sanitize_pkg_spec_version(v[pkg_param], v.version) - with self.runner(['notest', 'locallib', 'mirror', 'mirror_only', 'installdeps', 'pkg_spec'], output_process=process) as ctx: + with self.runner([ + 'notest', + 'locallib', + 'mirror', + 'mirror_only', + 'installdeps', + 'install_recommendations', + 'install_suggestions', + 'pkg_spec' + ], output_process=process) as ctx: self.changed = ctx.run(pkg_spec=pkg_spec) From 02451152198e323bf5f39c460a2df44b889b696b Mon Sep 17 00:00:00 2001 From: ZephOne Date: Sat, 11 Jan 2025 22:40:29 +0100 Subject: [PATCH 7/7] Add test for cpanm --with-recommends --- tests/unit/plugins/modules/test_cpanm.yaml | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/unit/plugins/modules/test_cpanm.yaml b/tests/unit/plugins/modules/test_cpanm.yaml index ff4bd9c0f7e..22c035efe52 100644 --- a/tests/unit/plugins/modules/test_cpanm.yaml +++ b/tests/unit/plugins/modules/test_cpanm.yaml @@ -357,3 +357,43 @@ cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm) perl version 5.041005 (/usr/local/bin/perl) err: "" +- id: install_dancer_with_recommends + input: + name: Dancer2 + install_recommendations: true + output: + changed: true + mocks: + run_command: + - command: [/testbin/cpanm, --version] + environ: *env-def-true + rc: 0 + out: | + cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm) + perl version 5.041005 (/usr/local/bin/perl) + err: "" + - command: [/testbin/cpanm, --with-recommends, Dancer2] + environ: *env-def-true + rc: 0 + out: "" + err: "" +- id: install_dancer_with_suggests + input: + name: Dancer2 + install_suggestions: true + output: + changed: true + mocks: + run_command: + - command: [/testbin/cpanm, --version] + environ: *env-def-true + rc: 0 + out: | + cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm) + perl version 5.041005 (/usr/local/bin/perl) + err: "" + - command: [/testbin/cpanm, --with-suggests, Dancer2] + environ: *env-def-true + rc: 0 + out: "" + err: ""