Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/module_helper/library/msimple.py

raw
1 #!/usr/bin/python
2 # Copyright (c) 2021, Alexei Znamensky <[email protected]>
3 #
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = """
10 module: msimple
11 author: "Alexei Znamensky (@russoz)"
12 short_description: Simple module for testing
13 description:
14 - Simple module test description.
15 options:
16 a:
17 description: aaaa
18 type: int
19 b:
20 description: bbbb
21 type: str
22 c:
23 description: cccc
24 type: str
25 """
26
27 EXAMPLES = ""
28
29 RETURN = ""
30
31 from ansible_collections.community.general.plugins.module_utils._mh.deco import check_mode_skip
32 from ansible_collections.community.general.plugins.module_utils._module_helper import ModuleHelper
33
34
35 class MSimple(ModuleHelper):
36 output_params = ("a", "b", "c", "m")
37 module = dict(
38 argument_spec=dict(
39 a=dict(type="int", default=0),
40 b=dict(type="str"),
41 c=dict(type="str"),
42 m=dict(type="str"),
43 ),
44 supports_check_mode=True,
45 )
46
47 def __init_module__(self):
48 self.vars.set("value", None)
49 self.vars.set("abc", "abc", diff=True)
50
51 @check_mode_skip
52 def process_a3_bc(self):
53 if self.vars.a == 3:
54 self.vars["b"] = str(self.vars.b) * 3
55 self.vars["c"] = str(self.vars.c) * 3
56
57 def __run__(self):
58 if self.vars.m:
59 self.vars.msg = self.vars.m
60 if self.vars.a >= 100:
61 raise Exception("a >= 100")
62 if self.vars.c == "abc change":
63 self.vars["abc"] = "changed abc"
64 if self.vars.a == 2:
65 self.vars["b"] = str(self.vars.b) * 2
66 self.vars["c"] = str(self.vars.c) * 2
67 self.process_a3_bc()
68
69
70 def main():
71 msimple = MSimple()
72 msimple.run()
73
74
75 if __name__ == "__main__":
76 main()