Debian Codegraph @

ansible_collections/community/proxmox/plugins/modules/proxmox_acme_accounts_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_accounts_info
10 short_description: Retrieves the list of ACME accounts.
11 version_added: "2.0.0"
12 author: Clément Cruau (@PendaGTP)
13 description:
14 - Retrieves the list of ACME accounts.
15 - For information about one account, use M(community.proxmox.proxmox_acme_account_info).
16
17 extends_documentation_fragment:
18 - community.proxmox.proxmox.actiongroup_proxmox
19 - community.proxmox.proxmox.documentation
20 - community.proxmox.attributes
21 - community.proxmox.attributes.info_module
22
23 seealso:
24 - module: community.proxmox.proxmox_acme_account_info
25 description: Retrieve information about a single ACME account.
26 - module: community.proxmox.proxmox_acme_account
27 description: Create, update or delete an ACME account.
28 """
29
30 EXAMPLES = r"""
31 - name: List ACME account names
32 community.proxmox.proxmox_acme_accounts_info:
33 """
34
35 RETURN = r"""
36 accounts:
37 description: List of ACME account names (filenames).
38 returned: on success
39 type: list
40 elements: str
41 """
42
43 from ansible.module_utils.common.text.converters import to_native
44
45 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
46 ProxmoxAnsible,
47 create_proxmox_module,
48 )
49
50
51 def module_args():
52 return dict()
53
54
55 def module_options():
56 return {}
57
58
59 class ProxmoxClusterAcmeAccountsInfoAnsible(ProxmoxAnsible):
60 def run(self):
61 self.module.exit_json(
62 changed=False,
63 accounts=self._list_account_names(),
64 )
65
66 def _list_account_names(self):
67 try:
68 accounts = self.proxmox_api.cluster().acme().account().get()
69 except Exception as e:
70 self.module.fail_json(msg=f"Failed to list ACME accounts: {to_native(e)}")
71 names = []
72 for account in accounts:
73 names.append(account["name"])
74 return sorted(set(names))
75
76
77 def main():
78 module = create_proxmox_module(module_args(), **module_options())
79 proxmox = ProxmoxClusterAcmeAccountsInfoAnsible(module)
80
81 try:
82 proxmox.run()
83 except Exception as e:
84 module.fail_json(msg=f"An error occurred: {to_native(e)}")
85
86
87 if __name__ == "__main__":
88 main()