Debian Codegraph @

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

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2026, Clément Cruau (@PendaGTP) <[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_acme_certificates_info
10 short_description: Retrieves the list of certificates on a Proxmox VE node.
11 version_added: 2.0.0
12 author: Clément Cruau (@PendaGTP)
13 description:
14 - Retrieves the list of certificates on a Proxmox VE node.
15 - Also returns the ACME configuration (account and domains) from the node config.
16 options:
17 node_name:
18 description:
19 - The name of the Proxmox VE node to list certificates for.
20 type: str
21 required: true
22
23 extends_documentation_fragment:
24 - community.proxmox.proxmox.actiongroup_proxmox
25 - community.proxmox.proxmox.documentation
26 - community.proxmox.attributes
27 - community.proxmox.attributes.info_module
28
29 seealso:
30 - module: community.proxmox.proxmox_acme_certificate
31 """
32
33 EXAMPLES = r"""
34 - name: List certificates
35 community.proxmox.proxmox_acme_certificates_info:
36 node_name: pve-node-01
37 """
38
39 RETURN = r"""
40 account:
41 description: The ACME account name configured on the node.
42 returned: on success
43 type: str
44 domains:
45 description: The list of ACME domains configured on the node.
46 returned: on success
47 type: list
48 elements: dict
49 contains:
50 domain:
51 description: The domain name.
52 type: str
53 plugin:
54 description: The DNS plugin used for validation.
55 type: str
56 alias:
57 description: The alias domain used for DNS validation.
58 type: str
59 certificates:
60 description: List of certificates on the node.
61 returned: on success
62 type: list
63 elements: dict
64 contains:
65 certificate:
66 description: The PEM-encoded certificate data.
67 type: str
68 fingerprint:
69 description: The certificate fingerprint.
70 type: str
71 issuer:
72 description: The certificate issuer.
73 type: str
74 subject:
75 description: The certificate subject.
76 type: str
77 not_before:
78 description: The certificate start timestamp.
79 type: int
80 not_after:
81 description: The certificate expiration timestamp.
82 type: int
83 subject_alternative_names:
84 description: The certificate subject alternative names (SANs).
85 type: list
86 elements: str
87 """
88
89 from ansible.module_utils.common.text.converters import to_native
90
91 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
92 ProxmoxAnsible,
93 create_proxmox_module,
94 )
95 from ansible_collections.community.proxmox.plugins.module_utils.proxmox_acme_certificate import (
96 cert_info_to_ansible_result,
97 parse_acme_config,
98 )
99
100
101 def module_args():
102 return dict(
103 node_name=dict(type="str", required=True),
104 )
105
106
107 def module_options():
108 return {}
109
110
111 class ProxmoxAcmeCertificatesInfoAnsible(ProxmoxAnsible):
112 def __init__(self, module):
113 super().__init__(module)
114 self.params = module.params
115
116 def run(self):
117 node_name = self.params["node_name"]
118 acme_config = self._read_node_acme_config(node_name)
119 certificates = self._list_certificates(node_name)
120 self.module.exit_json(
121 changed=False,
122 account=acme_config["account"],
123 domains=acme_config["domains"],
124 certificates=[cert_info_to_ansible_result(c) for c in certificates],
125 )
126
127 def _read_node_acme_config(self, node_name):
128 try:
129 config = self.proxmox_api.nodes(node_name).config.get()
130 except Exception as e:
131 self.module.fail_json(msg=f"Failed to read node config for {node_name}: {to_native(e)}")
132 return parse_acme_config(config)
133
134 def _list_certificates(self, node_name):
135 try:
136 return self.proxmox_api.nodes(node_name).certificates.info.get()
137 except Exception as e:
138 self.module.fail_json(msg=f"Failed to list certificates for node {node_name}: {to_native(e)}")
139
140
141 def main():
142 module = create_proxmox_module(module_args(), **module_options())
143 proxmox = ProxmoxAcmeCertificatesInfoAnsible(module)
144
145 try:
146 proxmox.run()
147 except Exception as e:
148 module.fail_json(msg=f"An error occurred: {to_native(e)}")
149
150
151 if __name__ == "__main__":
152 main()