ModuleHelper - lax handling of conflicting output (#5765)

* ModuleHelper - lax handling of conflicting output

* add changelog fragment

* only create _var when really needed

* adjust changelog

* Update changelogs/fragments/5765-mh-lax-output-conflict.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2023-01-07 22:21:13 +13:00 committed by GitHub
parent 02431341b7
commit dc531b183d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 13 deletions

View file

@ -57,6 +57,8 @@ class MSimple(ModuleHelper):
self.vars['c'] = str(self.vars.c) * 3
def __run__(self):
if self.vars.m:
self.vars.msg = self.vars.m
if self.vars.a >= 100:
raise Exception("a >= 100")
if self.vars.c == "abc change":
@ -66,9 +68,6 @@ 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

@ -2,7 +2,7 @@
# 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)
- name: test msimple conflict output (set a=80)
msimple:
a: 80
register: simple1
@ -15,7 +15,7 @@
- simple1 is not changed
- simple1.value is none
- name: test msimple 2
- name: test msimple conflict output 2
msimple:
a: 80
m: a message in a bottle
@ -28,4 +28,27 @@
- simple1.abc == "abc"
- simple1 is not changed
- simple1.value is none
- 'simple2._msg == "a message in a bottle"'
- >
"_msg" not in simple2
- >
simple2.msg == "a message in a bottle"
- name: test msimple 3
msimple:
a: 101
m: a message in a bottle
ignore_errors: yes
register: simple3
- name: assert simple3
assert:
that:
- simple3.a == 101
- >
simple3.msg == "Module failed with exception: a >= 100"
- >
simple3._msg == "a message in a bottle"
- simple3.abc == "abc"
- simple3 is failed
- simple3 is not changed
- simple3.value is none