1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/module_helper/library/msimple.py
patchback[bot] 4ea084cc29
[PR #5755/b49bf081 backport][stable-4] ModuleHelper - fix bug when adjusting 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 b49bf081f8)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2023-01-04 21:40:50 +01:00

78 lines
1.9 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2021, Alexei Znamensky <russoz@gmail.com>
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
module: msimple
author: "Alexei Znamensky (@russoz)"
short_description: Simple module for testing
description:
- Simple module test description.
options:
a:
description: aaaa
type: int
b:
description: bbbb
type: str
c:
description: cccc
type: str
'''
EXAMPLES = ""
RETURN = ""
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
from ansible_collections.community.general.plugins.module_utils.mh.deco import check_mode_skip
class MSimple(ModuleHelper):
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,
)
def __init_module__(self):
self.vars.set('value', None)
self.vars.set('abc', "abc", diff=True)
@check_mode_skip
def process_a3_bc(self):
if self.vars.a == 3:
self.vars['b'] = str(self.vars.b) * 3
self.vars['c'] = str(self.vars.c) * 3
def __run__(self):
if self.vars.a >= 100:
raise Exception("a >= 100")
if self.vars.c == "abc change":
self.vars['abc'] = "changed abc"
if self.vars.get('a', 0) == 2:
self.vars['b'] = str(self.vars.b) * 2
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()
msimple.run()
if __name__ == '__main__':
main()