From 64ea88c7f2944316ddd301d5dd11d9be0f2159b0 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 27 Jun 2022 19:49:49 +0200 Subject: [PATCH 1/3] Change Proxmox `agent` argument to string. --- plugins/modules/cloud/misc/proxmox_kvm.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index 774a926f598..7af2d680308 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -25,7 +25,9 @@ agent: description: - Specify if the QEMU Guest Agent should be enabled/disabled. - type: bool + - Since community.general 5.5.0, this can also be a string instead of a boolean. + This allows to specify values such as C(enabled=1,fstrim_cloned_disks=1). + type: str args: description: - Pass arbitrary arguments to kvm. @@ -809,6 +811,7 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.text.converters import to_native +from ansible.module_utils.parsing.convert_bool import boolean def parse_mac(netstr): @@ -960,7 +963,17 @@ def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update kwargs.update(kwargs[k]) del kwargs[k] - # Rename numa_enabled to numa. According the API documentation + # Map bool to string, according to API documentation. + try: + if boolean(kwargs['agent'], strict=True): + kwargs['agent'] = 'enabled=1' + else: + kwargs['agent'] = 'enabled=0' + except TypeError: + # Not something that Ansible would parse as a boolean. + pass + + # Rename numa_enabled to numa, according the API documentation if 'numa_enabled' in kwargs: kwargs['numa'] = kwargs['numa_enabled'] del kwargs['numa_enabled'] @@ -1040,7 +1053,7 @@ def main(): module_args = proxmox_auth_argument_spec() kvm_args = dict( acpi=dict(type='bool'), - agent=dict(type='bool'), + agent=dict(type='str'), args=dict(type='str'), autostart=dict(type='bool'), balloon=dict(type='int'), From f4864724fecc632307f21842775af89ec54e4432 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 11 Aug 2022 09:24:18 +0200 Subject: [PATCH 2/3] Add changelog entry. --- changelogs/fragments/5107-proxmox-agent-argument.yaml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/5107-proxmox-agent-argument.yaml diff --git a/changelogs/fragments/5107-proxmox-agent-argument.yaml b/changelogs/fragments/5107-proxmox-agent-argument.yaml new file mode 100644 index 00000000000..78e7927da19 --- /dev/null +++ b/changelogs/fragments/5107-proxmox-agent-argument.yaml @@ -0,0 +1,2 @@ +minor_changes: + - proxmox_kvm - allow ``agent`` argument to be a string (https://github.com/ansible-collections/community.general/pull/5107). From b91bf5029567514d8121a1c35c238129f6608aed Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 13 Aug 2022 01:31:26 +0200 Subject: [PATCH 3/3] Pass boolean directly to `proxmoxer`. --- plugins/modules/cloud/misc/proxmox_kvm.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index 7af2d680308..ff02a338666 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -963,12 +963,9 @@ def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update kwargs.update(kwargs[k]) del kwargs[k] - # Map bool to string, according to API documentation. try: - if boolean(kwargs['agent'], strict=True): - kwargs['agent'] = 'enabled=1' - else: - kwargs['agent'] = 'enabled=0' + # The API also allows booleans instead of e.g. `enabled=1` for backward-compatibility. + kwargs['agent'] = boolean(kwargs['agent'], strict=True) except TypeError: # Not something that Ansible would parse as a boolean. pass