From 46cbf60c2d70a7913fc146dedcf8e9ccd08b11b0 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 08:22:38 +0100 Subject: [PATCH] [PR #7405/f7267c71 backport][stable-6] Fix the ability to run Composer "working_dir" dependent commands (#7459) Fix the ability to run Composer "working_dir" dependent commands (#7405) * pass the working_dir to all composer command invocations that are not global * add changelog fragment * Update changelog fragment Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit f7267c7123f178cfd0b39ebe9c6149fe3f63e477) Co-authored-by: Xavier Lacot --- .../fragments/3787-pass-composer-working-dir.yml | 2 ++ plugins/modules/composer.py | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/3787-pass-composer-working-dir.yml diff --git a/changelogs/fragments/3787-pass-composer-working-dir.yml b/changelogs/fragments/3787-pass-composer-working-dir.yml new file mode 100644 index 0000000000..19687d7723 --- /dev/null +++ b/changelogs/fragments/3787-pass-composer-working-dir.yml @@ -0,0 +1,2 @@ +bugfixes: + - composer - fix impossible to run ``working_dir`` dependent commands. The module was throwing an error when trying to run a ``working_dir`` dependent command, because it tried to get the command help without passing the ``working_dir`` (https://github.com/ansible-collections/community.general/issues/3787). diff --git a/plugins/modules/composer.py b/plugins/modules/composer.py index 793abcda18..890fff4556 100644 --- a/plugins/modules/composer.py +++ b/plugins/modules/composer.py @@ -170,10 +170,15 @@ def get_available_options(module, command='install'): return command_help_json['definition']['options'] -def composer_command(module, command, arguments="", options=None, global_command=False): +def composer_command(module, command, arguments="", options=None): if options is None: options = [] + global_command = module.params['global_command'] + + if not global_command: + options.extend(['--working-dir', "'%s'" % module.params['working_dir']]) + if module.params['executable'] is None: php_path = module.get_bin_path("php", True, ["/usr/local/bin"]) else: @@ -217,7 +222,6 @@ def main(): module.fail_json(msg="Use the 'arguments' param for passing arguments with the 'command'") arguments = module.params['arguments'] - global_command = module.params['global_command'] available_options = get_available_options(module=module, command=command) options = [] @@ -234,9 +238,6 @@ def main(): option = "--%s" % option options.append(option) - if not global_command: - options.extend(['--working-dir', "'%s'" % module.params['working_dir']]) - option_params = { 'prefer_source': 'prefer-source', 'prefer_dist': 'prefer-dist', @@ -260,7 +261,7 @@ def main(): else: module.exit_json(skipped=True, msg="command '%s' does not support check mode, skipping" % command) - rc, out, err = composer_command(module, command, arguments, options, global_command) + rc, out, err = composer_command(module, command, arguments, options) if rc != 0: output = parse_out(err)