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

ModuleHelper: CmdMixin custom function for processing cmd results (#2564)

* MH: custom function for processing cmd results

* added changelog fragment

* removed case of process_output being a str
This commit is contained in:
Alexei Znamensky 2021-05-21 05:43:16 +12:00 committed by GitHub
parent 452a185a23
commit 1403f5edcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- module_helper module utils - method ``CmdMixin.run_command()`` now accepts ``process_output`` specifying a function to process the outcome of the underlying ``module.run_command()`` (https://github.com/ansible-collections/community.general/pull/2564).

View file

@ -152,7 +152,7 @@ class CmdMixin(object):
def process_command_output(self, rc, out, err):
return rc, out, err
def run_command(self, extra_params=None, params=None, *args, **kwargs):
def run_command(self, extra_params=None, params=None, process_output=None, *args, **kwargs):
self.vars.cmd_args = self._calculate_args(extra_params, params)
options = dict(self.run_command_fixed_options)
env_update = dict(options.get('environ_update', {}))
@ -164,4 +164,9 @@ class CmdMixin(object):
options.update(kwargs)
rc, out, err = self.module.run_command(self.vars.cmd_args, *args, **options)
self.update_output(rc=rc, stdout=out, stderr=err)
return self.process_command_output(rc, out, err)
if process_output is None:
_process = self.process_command_output
else:
_process = process_output
return _process(rc, out, err)