Debian Codegraph @

ansible_collections/community/proxmox/plugins/modules/proxmox_acme_account_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_account_info
10 short_description: Retrieves information about a specific ACME account.
11 version_added: "2.0.0"
12 author: Clément Cruau (@PendaGTP)
13 description:
14 - Retrieves information about a specific ACME account.
15 - To list all ACME account names, use M(community.proxmox.proxmox_acme_accounts_info).
16 - Requires C(root@pam) authentication.
17 options:
18 name:
19 description:
20 - The ACME account name (filename).
21 type: str
22 required: true
23
24 extends_documentation_fragment:
25 - community.proxmox.proxmox.actiongroup_proxmox
26 - community.proxmox.proxmox.documentation
27 - community.proxmox.attributes
28 - community.proxmox.attributes.info_module
29
30 seealso:
31 - module: community.proxmox.proxmox_acme_accounts_info
32 description: List ACME account names.
33 - module: community.proxmox.proxmox_acme_account
34 description: Create, update or delete an ACME account.
35 """
36
37 EXAMPLES = r"""
38 - name: Get ACME account example
39 community.proxmox.proxmox_acme_account_info:
40 name: example
41 """
42
43 RETURN = r"""
44 name:
45 description: The ACME account name (filename).
46 returned: on success
47 type: str
48 account:
49 description: ACME account data returned by the API.
50 returned: on success
51 type: dict
52 contains:
53 contact:
54 description: Contact email addresses (normalized from C(mailto:)).
55 type: list
56 elements: str
57 created_at:
58 description: Account creation timestamp from the ACME API.
59 type: str
60 status:
61 description: Account status (for example V(valid), V(deactivated), V(revoked)).
62 type: str
63 directory:
64 description: Directory URL of the ACME account.
65 returned: on success
66 type: str
67 location:
68 description: Account resource URL from the ACME CA.
69 returned: on success
70 type: str
71 tos:
72 description: Terms of service URL for the account.
73 returned: on success
74 type: str
75 """
76
77 from ansible.module_utils.common.text.converters import to_native
78
79 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
80 ProxmoxAnsible,
81 create_proxmox_module,
82 is_not_found_error,
83 )
84 from ansible_collections.community.proxmox.plugins.module_utils.proxmox_acme_account import (
85 acme_account_to_ansible_result,
86 )
87
88
89 def module_args():
90 return dict(
91 name=dict(type="str", required=True),
92 )
93
94
95 def module_options():
96 return {}
97
98
99 class ProxmoxClusterAcmeAccountInfoAnsible(ProxmoxAnsible):
100 def __init__(self, module):
101 super().__init__(module)
102 self.params = module.params
103
104 def run(self):
105 name = self.params["name"]
106 data = self._fetch_account(name)
107 if data is None:
108 self.module.fail_json(msg=f"ACME account {name} does not exist", name=name)
109
110 result = acme_account_to_ansible_result(data)
111 self.module.exit_json(
112 changed=False,
113 name=name,
114 **result,
115 )
116
117 def _fetch_account(self, name):
118 try:
119 return self.proxmox_api.cluster().acme().account()(name).get()
120 except Exception as e:
121 if is_not_found_error(e):
122 return None
123 self.module.fail_json(msg=f"Failed to read ACME account {name}: {to_native(e)}")
124
125
126 def main():
127 module = create_proxmox_module(module_args(), **module_options())
128 proxmox = ProxmoxClusterAcmeAccountInfoAnsible(module)
129
130 try:
131 proxmox.run()
132 except Exception as e:
133 module.fail_json(msg=f"An error occurred: {to_native(e)}")
134
135
136 if __name__ == "__main__":
137 main()