Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/module_helper/library/mdepfail.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: mdepfail
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 import _deps as deps
32 from ansible_collections.community.general.plugins.module_utils._module_helper import ModuleHelper
33
34 with deps.declare("nopackagewiththisname"):
35 import nopackagewiththisname # noqa: F401, pylint: disable=unused-import # type: ignore[import-not-found]
36
37
38 class MSimple(ModuleHelper):
39 output_params = ("a", "b", "c")
40 module = dict(
41 argument_spec=dict(
42 a=dict(type="int"),
43 b=dict(type="str"),
44 c=dict(type="str"),
45 ),
46 )
47
48 def __init_module__(self):
49 self.vars.set("value", None)
50 self.vars.set("abc", "abc", diff=True)
51 deps.validate(self.module)
52
53 def __run__(self):
54 if (0 if self.vars.a is None else self.vars.a) >= 100:
55 raise Exception("a >= 100")
56 if self.vars.c == "abc change":
57 self.vars["abc"] = "changed abc"
58 if self.vars.a == 2:
59 self.vars["b"] = str(self.vars.b) * 2
60 self.vars["c"] = str(self.vars.c) * 2
61
62
63 def main():
64 msimple = MSimple()
65 msimple.run()
66
67
68 if __name__ == "__main__":
69 main()