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

[PR #5755/b49bf081 backport][stable-6] ModuleHelper - fix bug when adjusting conflicting output (#5758)

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 b49bf081f8)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-01-04 21:40:56 +01:00 committed by GitHub
parent 80206b5a53
commit c355f93d62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 2 deletions

View file

@ -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).

View file

@ -60,7 +60,7 @@ class ModuleHelper(DeprecateAttrsMixin, VarsMixin, DependencyMixin, ModuleHelper
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]

View file

@ -35,12 +35,13 @@ from ansible_collections.community.general.plugins.module_utils.mh.deco import c
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,
)
@ -65,6 +66,9 @@ class MSimple(ModuleHelper):
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()

View file

@ -3,6 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
- include_tasks: msimple.yml
- include_tasks: msimple_output_conflict.yml
- include_tasks: mdepfail.yml
- include_tasks: mstate.yml
- include_tasks: msimpleda.yml

View file

@ -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"'