From 123b5a9a3cbf992420d4836aeac3b612af4d51d9 Mon Sep 17 00:00:00 2001 From: Jeffrey van Pelt Date: Sat, 17 Apr 2021 10:08:41 +0200 Subject: [PATCH] Proxmox inv fix agent string parsing (#2245) * Added handling for commas in the agent field for agent configuration * Removed test statement * Added changelog fragment * Fixed spelling on fragment :-) --- .../fragments/2245-proxmox_fix_agent_string_handling.yml | 3 +++ plugins/inventory/proxmox.py | 4 +++- tests/unit/plugins/inventory/test_proxmox.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/2245-proxmox_fix_agent_string_handling.yml diff --git a/changelogs/fragments/2245-proxmox_fix_agent_string_handling.yml b/changelogs/fragments/2245-proxmox_fix_agent_string_handling.yml new file mode 100644 index 0000000000..3eae94f4ea --- /dev/null +++ b/changelogs/fragments/2245-proxmox_fix_agent_string_handling.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - proxmox inventory - added handling of commas in KVM agent configuration string (https://github.com/ansible-collections/community.general/pull/2245). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 036c3dc7bf..44b807f230 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -281,7 +281,9 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): parsed_value = [tag.strip() for tag in value.split(",")] self.inventory.set_variable(name, parsed_key, parsed_value) - if config == 'agent' and int(value): + # The first field in the agent string tells you whether the agent is enabled + # the rest of the comma separated string is extra config for the agent + if config == 'agent' and int(value.split(',')[0]): agent_iface_key = self.to_safe('%s%s' % (key, "_interfaces")) agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype) if agent_iface_value: diff --git a/tests/unit/plugins/inventory/test_proxmox.py b/tests/unit/plugins/inventory/test_proxmox.py index ee6c0e2963..a68203b725 100644 --- a/tests/unit/plugins/inventory/test_proxmox.py +++ b/tests/unit/plugins/inventory/test_proxmox.py @@ -205,7 +205,7 @@ def get_json(url): "hotplug": "network,disk,usb", "scsi0": "local-lvm:vm-101-disk-0,size=8G", "net0": "virtio=ff:ff:ff:ff:ff:ff,bridge=vmbr0,firewall=1", - "agent": "1", + "agent": "1,fstrim_cloned_disks=1", "bios": "seabios", "ide0": "local-lvm:vm-101-cloudinit,media=cdrom,size=4M", "boot": "cdn",