1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

module_helper cmd - added feature flag to control whether CmdMixin adds rc, out and err t… (#2922)

* added feature flag to control whether CmdMixin adds rc, out and err to the result of the module

* added changelog fragment

* changed from a global flag to parameters in run_command

* updated changelog

* fixed brainless copy-paste of yours truly
This commit is contained in:
Alexei Znamensky 2021-07-11 11:43:40 +12:00 committed by GitHub
parent 7a41833e59
commit c5cbe2943b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- module_helper module utils - added feature flag parameters to ``CmdMixin`` to control whether ``rc``, ``out`` and ``err`` are automatically added to the module output (https://github.com/ansible-collections/community.general/pull/2922).

View file

@ -152,7 +152,14 @@ class CmdMixin(object):
def process_command_output(self, rc, out, err): def process_command_output(self, rc, out, err):
return rc, out, err return rc, out, err
def run_command(self, extra_params=None, params=None, process_output=None, *args, **kwargs): def run_command(self,
extra_params=None,
params=None,
process_output=None,
publish_rc=True,
publish_out=True,
publish_err=True,
*args, **kwargs):
self.vars.cmd_args = self._calculate_args(extra_params, params) self.vars.cmd_args = self._calculate_args(extra_params, params)
options = dict(self.run_command_fixed_options) options = dict(self.run_command_fixed_options)
options['check_rc'] = options.get('check_rc', self.check_rc) options['check_rc'] = options.get('check_rc', self.check_rc)
@ -166,7 +173,12 @@ class CmdMixin(object):
self.update_output(force_lang=self.force_lang) self.update_output(force_lang=self.force_lang)
options['environ_update'] = env_update 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(self.vars.cmd_args, *args, **options)
self.update_output(rc=rc, stdout=out, stderr=err) 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 process_output is None: if process_output is None:
_process = self.process_command_output _process = self.process_command_output
else: else: