Skip to content

Commit

Permalink
[PR #5755/b49bf081 backport][stable-4] ModuleHelper - fix bug when ad…
Browse files Browse the repository at this point in the history
…justing conflicting output (#5756)

ModuleHelper - fix bug when adjusting conflicting output (#5755)

* ModuleHelper - fix bug when adjusting conflicting output

* add changelog fragment

* remove commented test code

(cherry picked from commit b49bf08)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
  • Loading branch information
patchback[bot] and russoz authored Jan 4, 2023
1 parent c5c8dec commit 4ea084c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/5755-mh-fix-output-conflict.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ModuleHelper - fix bug when adjusting the name of reserved output variables (https://github.com/ansible-collections/community.general/pull/5755).
2 changes: 1 addition & 1 deletion plugins/module_utils/mh/module_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def output(self):
vars_diff = self.vars.diff() or {}
result['diff'] = dict_merge(dict(diff), vars_diff)

for varname in result:
for varname in list(result):
if varname in self._output_conflict_list:
result["_" + varname] = result[varname]
del result[varname]
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/targets/module_helper/library/msimple.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@


class MSimple(ModuleHelper):
output_params = ('a', 'b', 'c')
output_params = ('a', 'b', 'c', 'm')
module = dict(
argument_spec=dict(
a=dict(type='int', default=0),
b=dict(type='str'),
c=dict(type='str'),
m=dict(type='str'),
),
supports_check_mode=True,
)
Expand All @@ -64,6 +65,9 @@ def __run__(self):
self.vars['c'] = str(self.vars.c) * 2
self.process_a3_bc()

if self.vars.m:
self.vars.msg = self.vars.m


def main():
msimple = MSimple()
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/module_helper/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- include_tasks: msimple.yml
- include_tasks: msimple_output_conflict.yml
- include_tasks: mdepfail.yml
- include_tasks: mstate.yml
- include_tasks: msimpleda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2023, Alexei Znamensky
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- name: test msimple (set a=80)
msimple:
a: 80
register: simple1

- name: assert simple1
assert:
that:
- simple1.a == 80
- simple1.abc == "abc"
- simple1 is not changed
- simple1.value is none

- name: test msimple 2
msimple:
a: 80
m: a message in a bottle
register: simple2

- name: assert simple2
assert:
that:
- simple1.a == 80
- simple1.abc == "abc"
- simple1 is not changed
- simple1.value is none
- 'simple2._msg == "a message in a bottle"'

0 comments on commit 4ea084c

Please sign in to comment.