Debian Codegraph @

ansible_collections/community/proxmox/plugins/modules/proxmox_cluster_join_info.py

raw
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2025, Florian Paul Azim Hoberg (@gyptazy) <[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
8 DOCUMENTATION = r"""
9 module: proxmox_cluster_join_info
10 version_added: 1.0.0
11 short_description: Retrieve the join information of the Proxmox VE cluster
12 description:
13 - Retrieve the join information of the Proxmox VE cluster.
14 author: Florian Paul Azim Hoberg (@gyptazy)
15 extends_documentation_fragment:
16 - community.proxmox.proxmox.actiongroup_proxmox
17 - community.proxmox.proxmox.documentation
18 - community.proxmox.attributes
19 - community.proxmox.attributes.info_module
20 """
21
22 EXAMPLES = r"""
23 - name: List existing Proxmox VE cluster join information
24 community.proxmox.proxmox_cluster_join_info:
25 register: proxmox_cluster_join
26 """
27
28 RETURN = r"""
29 cluster_join:
30 description: List of Proxmox VE nodes including the join information within the cluster.
31 returned: always, but can be empty
32 type: list
33 elements: dict
34 contains:
35 config_digest:
36 description: Digest of the cluster configuration.
37 type: str
38 sample: "aef68412f7976505ed083e6173b96274a281da25"
39 nodelist:
40 description: List of nodes in the cluster.
41 type: list
42 elements: dict
43 contains:
44 name:
45 description: Node name.
46 type: str
47 sample: "pve2"
48 nodeid:
49 description: Node ID.
50 type: str
51 sample: "1"
52 pve_addr:
53 description: Proxmox VE address.
54 type: str
55 sample: "10.10.10.159"
56 pve_fp:
57 description: Proxmox VE fingerprint.
58 type: str
59 sample: "08:B5:B2:F9:EC:01:0B:D0:..."
60 quorum_votes:
61 description: Quorum votes assigned to the node.
62 type: str
63 sample: "1"
64 ring0_addr:
65 description: Address for ring0.
66 type: str
67 sample: "vmbr0"
68 preferred_node:
69 description: The preferred cluster node.
70 type: str
71 sample: "pve2"
72 totem:
73 description: Totem protocol configuration.
74 type: dict
75 contains:
76 cluster_name:
77 description: Cluster name from totem.
78 type: str
79 sample: "devcluster"
80 config_version:
81 description: Config version.
82 type: str
83 sample: "1"
84 interface:
85 description: Interface configuration.
86 type: dict
87 ip_version:
88 description: IP version.
89 type: str
90 sample: "ipv4-6"
91 link_mode:
92 description: Link mode.
93 type: str
94 sample: "passive"
95 secauth:
96 description: Whether secure authentication is on.
97 type: str
98 sample: "on"
99 version:
100 description: Totem protocol version.
101 type: str
102 sample: "2"
103 """
104
105
106 import traceback
107
108 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
109 ProxmoxAnsible,
110 create_proxmox_module,
111 )
112
113 try:
114 import proxmoxer
115 except ImportError:
116 PROXMOXER_LIBRARY = False
117 PROXMOXER_LIBRARY_IMPORT_ERROR = traceback.format_exc()
118 else:
119 PROXMOXER_LIBRARY = True
120 PROXMOXER_LIBRARY_IMPORT_ERROR = None
121
122
123 def module_args():
124 return dict()
125
126
127 def module_options():
128 return {}
129
130
131 class ProxmoxClusterJoinInfoAnsible(ProxmoxAnsible):
132 def get_cluster_join(self):
133 try:
134 return self.proxmox_api.cluster.config.join.get()
135 except proxmoxer.core.ResourceException:
136 self.module.fail_json(msg="Node is not part of a cluster and does not have any join information.")
137 except Exception as e:
138 self.module.fail_json(msg=f"Error obtaining cluster join information: {str(e)}")
139
140
141 def main():
142 module = create_proxmox_module(module_args(), **module_options())
143 proxmox = ProxmoxClusterJoinInfoAnsible(module)
144
145 result = dict(changed=False)
146
147 cluster_join = proxmox.get_cluster_join()
148 result["cluster_join"] = cluster_join
149
150 module.exit_json(**result)
151
152
153 if __name__ == "__main__":
154 main()