Debian Codegraph @

ansible_collections/community/general/plugins/modules/pacemaker_info.py

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2025, Dexter Le <[email protected]>
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 = r"""
10 module: pacemaker_info
11 short_description: Gather information about Pacemaker cluster
12 author:
13 - Dexter Le (@munchtoast)
14 version_added: 11.2.0
15 description:
16 - Gather information about a Pacemaker cluster.
17 extends_documentation_fragment:
18 - community.general._attributes
19 - community.general._attributes.info_module
20 """
21
22 EXAMPLES = r"""
23 - name: Gather Pacemaker cluster info
24 community.general.pacemaker_info:
25 register: result
26
27 - name: Debug cluster info
28 ansible.builtin.debug:
29 msg: "{{ result }}"
30 """
31
32 RETURN = r"""
33 version:
34 description: Pacemaker CLI version
35 returned: always
36 type: str
37 cluster_info:
38 description: Cluster information such as the name, UUID, and nodes.
39 returned: always
40 type: dict
41 resource_info:
42 description: All resources available on the cluster and their status.
43 returned: success
44 type: dict
45 stonith_info:
46 description: All STONITH information on the cluster.
47 returned: success
48 type: dict
49 constraint_info:
50 description: All cluster resource constraints on the cluster.
51 returned: success
52 type: dict
53 property_info:
54 description: All properties present on the cluster.
55 returned: success
56 type: dict
57 """
58
59 import json
60
61 from ansible_collections.community.general.plugins.module_utils._module_helper import ModuleHelper
62 from ansible_collections.community.general.plugins.module_utils._pacemaker import pacemaker_runner
63
64
65 class PacemakerInfo(ModuleHelper):
66 module = dict(
67 argument_spec=dict(),
68 supports_check_mode=True,
69 )
70 info_vars = {
71 "cluster_info": "cluster",
72 "resource_info": "resource",
73 "stonith_info": "stonith",
74 "constraint_info": "constraint",
75 "property_info": "property",
76 }
77 output_params = list(info_vars.keys())
78
79 def __init_module__(self):
80 self.runner = pacemaker_runner(self.module)
81 with self.runner("version") as ctx:
82 rc, out, err = ctx.run()
83 self.vars.version = out.strip()
84
85 def _process_command_output(self, cli_action=""):
86 def process(rc, out, err):
87 if rc != 0:
88 self.do_raise(f"pcs {cli_action} config failed with error (rc={rc}): {err}")
89 out = json.loads(out)
90 return None if out == "" else out
91
92 return process
93
94 def _get_info(self, cli_action):
95 with self.runner(
96 "cli_action config output_format", output_process=self._process_command_output(cli_action)
97 ) as ctx:
98 return ctx.run(cli_action=cli_action, output_format="json")
99
100 def __run__(self):
101 for key, cli_action in sorted(self.info_vars.items()):
102 self.vars.set(key, self._get_info(cli_action))
103
104
105 def main():
106 PacemakerInfo.execute()
107
108
109 if __name__ == "__main__":
110 main()