From 927356dad3dd1f2c7c1cd03b8cd5bd24e7b43e9e Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Mon, 1 Nov 2021 08:35:21 +1300 Subject: [PATCH] mh/mixins/cmd - added publish_cmd parameter to CmdModuleHelper.run_command() (#3648) * added publish_cmd parameter to CmdModuleHelper.run_command() * added changelog fragment * Update plugins/module_utils/mh/mixins/cmd.py Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- changelogs/fragments/3648-mh-cmd-publish-cmd.yaml | 2 ++ plugins/module_utils/mh/mixins/cmd.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/3648-mh-cmd-publish-cmd.yaml diff --git a/changelogs/fragments/3648-mh-cmd-publish-cmd.yaml b/changelogs/fragments/3648-mh-cmd-publish-cmd.yaml new file mode 100644 index 0000000000..9088ec4c48 --- /dev/null +++ b/changelogs/fragments/3648-mh-cmd-publish-cmd.yaml @@ -0,0 +1,2 @@ +minor_changes: + - module_helper module utils - added feature flag parameter to ``CmdMixin`` to control whether ``cmd_args`` is automatically added to the module output (https://github.com/ansible-collections/community.general/pull/3648). diff --git a/plugins/module_utils/mh/mixins/cmd.py b/plugins/module_utils/mh/mixins/cmd.py index e07e144224..88b89d159b 100644 --- a/plugins/module_utils/mh/mixins/cmd.py +++ b/plugins/module_utils/mh/mixins/cmd.py @@ -158,8 +158,9 @@ class CmdMixin(object): publish_rc=True, publish_out=True, publish_err=True, + publish_cmd=True, *args, **kwargs): - self.vars.cmd_args = self._calculate_args(extra_params, params) + cmd_args = self._calculate_args(extra_params, params) options = dict(self.run_command_fixed_options) options['check_rc'] = options.get('check_rc', self.check_rc) options.update(kwargs) @@ -171,13 +172,15 @@ class CmdMixin(object): }) self.update_output(force_lang=self.force_lang) options['environ_update'] = env_update - rc, out, err = self.module.run_command(self.vars.cmd_args, *args, **options) + rc, out, err = self.module.run_command(cmd_args, *args, **options) if publish_rc: self.update_output(rc=rc) if publish_out: self.update_output(stdout=out) if publish_err: self.update_output(stderr=err) + if publish_cmd: + self.update_output(cmd_args=cmd_args) if process_output is None: _process = self.process_command_output else: