diff --git a/changelogs/fragments/5037-xfconf-add-cmd-output.yaml b/changelogs/fragments/5037-xfconf-add-cmd-output.yaml new file mode 100644 index 0000000000..f32926c711 --- /dev/null +++ b/changelogs/fragments/5037-xfconf-add-cmd-output.yaml @@ -0,0 +1,2 @@ +minor_changes: + - xfconf - add ``stdout``, ``stderr`` and ``cmd`` to the module results (https://github.com/ansible-collections/community.general/pull/5037). diff --git a/plugins/modules/system/xfconf.py b/plugins/modules/system/xfconf.py index 7f34118c49..8144602916 100644 --- a/plugins/modules/system/xfconf.py +++ b/plugins/modules/system/xfconf.py @@ -143,6 +143,24 @@ RETURN = ''' returned: success type: any sample: '"96" or ["red", "blue", "green"]' + cmd: + description: + - A list with the resulting C(xfconf-query) command executed by the module. + returned: success + type: list + elements: str + version_added: 5.4.0 + sample: + - /usr/bin/xfconf-query + - --channel + - xfce4-panel + - --property + - /plugins/plugin-19/timezone + - --create + - --type + - string + - --set + - Pacific/Auckland ''' from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper @@ -207,6 +225,11 @@ class XFConfProperty(StateModuleHelper): def state_absent(self): with self.runner('channel property reset', check_mode_skip=True) as ctx: ctx.run(reset=True) + self.vars.stdout = ctx.results_out + self.vars.stderr = ctx.results_err + self.vars.cmd = ctx.cmd + if self.verbosity >= 4: + self.vars.run_info = ctx.run_info self.vars.value = None def state_present(self): @@ -233,6 +256,11 @@ class XFConfProperty(StateModuleHelper): with self.runner('channel property create force_array values_and_types', check_mode_skip=True) as ctx: ctx.run(create=True, force_array=self.vars.is_array, values_and_types=(self.vars.value, value_type)) + self.vars.stdout = ctx.results_out + self.vars.stderr = ctx.results_err + self.vars.cmd = ctx.cmd + if self.verbosity >= 4: + self.vars.run_info = ctx.run_info if not self.vars.is_array: self.vars.value = self.vars.value[0] diff --git a/tests/unit/plugins/modules/system/test_xfconf.py b/tests/unit/plugins/modules/system/test_xfconf.py index 7743d07cd4..d97ce85e49 100644 --- a/tests/unit/plugins/modules/system/test_xfconf.py +++ b/tests/unit/plugins/modules/system/test_xfconf.py @@ -268,7 +268,7 @@ def test_xfconf(mocker, capfd, patch_xfconf, testcase): # Mock function used for running commands first call_results = [item[2] for item in testcase['run_command.calls']] mock_run_command = mocker.patch( - 'ansible_collections.community.general.plugins.module_utils.mh.module_helper.AnsibleModule.run_command', + 'ansible.module_utils.basic.AnsibleModule.run_command', side_effect=call_results) # Try to run test case @@ -296,6 +296,11 @@ def test_xfconf(mocker, capfd, patch_xfconf, testcase): print("expected args list =\n%s" % expected_call_args_list) assert call_args_list == expected_call_args_list + expected_cmd, dummy, expected_res = testcase['run_command.calls'][-1] + assert results['cmd'] == expected_cmd + assert results['stdout'] == expected_res[1] + assert results['stderr'] == expected_res[2] + for conditional_test_result in ('msg', 'value', 'previous_value'): if conditional_test_result in testcase: assert conditional_test_result in results, "'{0}' not found in {1}".format(conditional_test_result, results)