| 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_plugin_info |
| 10 |
short_description: Retrieves a single ACME plugin |
| 11 |
version_added: "2.0.0" |
| 12 |
author: |
| 13 |
- Clément Cruau (@PendaGTP) |
| 14 |
description: |
| 15 |
- Retrieves a single ACME plugin by plugin ID name. |
| 16 |
attributes: |
| 17 |
check_mode: |
| 18 |
support: full |
| 19 |
diff_mode: |
| 20 |
support: none |
| 21 |
options: |
| 22 |
name: |
| 23 |
description: |
| 24 |
- The ACME Plugin ID name. |
| 25 |
type: str |
| 26 |
required: true |
| 27 |
aliases: ["id"] |
| 28 |
|
| 29 |
seealso: |
| 30 |
- module: community.proxmox.proxmox_acme_plugin_dns |
| 31 |
description: Manage ACME DNS plugins on a Proxmox VE. |
| 32 |
- module: community.proxmox.proxmox_acme_plugins_info |
| 33 |
description: Retrieves the list of ACME plugins. |
| 34 |
|
| 35 |
extends_documentation_fragment: |
| 36 |
- community.proxmox.proxmox.actiongroup_proxmox |
| 37 |
- community.proxmox.proxmox.documentation |
| 38 |
- community.proxmox.attributes |
| 39 |
""" |
| 40 |
|
| 41 |
EXAMPLES = r""" |
| 42 |
- name: Get ACME plugin example |
| 43 |
community.proxmox.proxmox_acme_plugin_info: |
| 44 |
name: example |
| 45 |
""" |
| 46 |
|
| 47 |
RETURN = r""" |
| 48 |
name: |
| 49 |
description: ACME plugin instance identifier. |
| 50 |
returned: on success |
| 51 |
type: str |
| 52 |
type: |
| 53 |
description: ACME challenge type (dns, standalone). |
| 54 |
returned: on success |
| 55 |
type: str |
| 56 |
plugin: |
| 57 |
description: API implementation name. |
| 58 |
returned: on success |
| 59 |
type: str |
| 60 |
data: |
| 61 |
description: Plugin settings as string key/value pairs (value are masked). |
| 62 |
returned: on success |
| 63 |
type: dict |
| 64 |
disable: |
| 65 |
description: Whether the plugin configuration is disabled. |
| 66 |
returned: on success |
| 67 |
type: bool |
| 68 |
validation_delay: |
| 69 |
description: Validation delay in seconds. |
| 70 |
returned: on success |
| 71 |
type: int |
| 72 |
digest: |
| 73 |
description: Digest of the plugin configuration. |
| 74 |
returned: on success |
| 75 |
type: str |
| 76 |
""" |
| 77 |
|
| 78 |
from ansible.module_utils.common.text.converters import to_native |
| 79 |
|
| 80 |
from ansible_collections.community.proxmox.plugins.module_utils.proxmox import ( |
| 81 |
ProxmoxAnsible, |
| 82 |
create_proxmox_module, |
| 83 |
is_not_found_error, |
| 84 |
) |
| 85 |
from ansible_collections.community.proxmox.plugins.module_utils.proxmox_acme_plugin import ( |
| 86 |
acme_plugin_to_ansible_result, |
| 87 |
) |
| 88 |
|
| 89 |
|
| 90 |
def module_args(): |
| 91 |
return dict( |
| 92 |
name=dict(type="str", required=True, aliases=["id"]), |
| 93 |
) |
| 94 |
|
| 95 |
|
| 96 |
def module_options(): |
| 97 |
return dict() |
| 98 |
|
| 99 |
|
| 100 |
class ProxmoxClusterAcmePluginInfoAnsible(ProxmoxAnsible): |
| 101 |
def __init__(self, module): |
| 102 |
super().__init__(module) |
| 103 |
self.params = module.params |
| 104 |
|
| 105 |
def run(self): |
| 106 |
name = self.params["name"] |
| 107 |
data = self._fetch_plugin(name) |
| 108 |
if data is None: |
| 109 |
self.module.fail_json(msg=f"ACME plugin {name} does not exist", name=name) |
| 110 |
|
| 111 |
result = acme_plugin_to_ansible_result(data) |
| 112 |
self.module.exit_json( |
| 113 |
changed=False, |
| 114 |
**result, |
| 115 |
) |
| 116 |
|
| 117 |
def _fetch_plugin(self, name): |
| 118 |
try: |
| 119 |
return self.proxmox_api.cluster().acme().plugins()(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 plugin {name}: {to_native(e)}") |
| 124 |
|
| 125 |
|
| 126 |
def main(): |
| 127 |
module = create_proxmox_module(module_args(), **module_options()) |
| 128 |
proxmox = ProxmoxClusterAcmePluginInfoAnsible(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() |