From aa03c71267f6f03123f1b534f726acec3d056fb9 Mon Sep 17 00:00:00 2001 From: ube Date: Tue, 12 Jul 2022 11:03:13 +0200 Subject: [PATCH] proxmox inventory: fix for agent enabled (#4910) * Update proxmox.py * Forgot a debug print. * pep * Check if int, old school way. * pep, once again. * Create 4910-fix-for-agent-enabled.yml * Must check the first listentry for enabled=1 * Update changelogs/fragments/4910-fix-for-agent-enabled.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../fragments/4910-fix-for-agent-enabled.yml | 2 ++ plugins/inventory/proxmox.py | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/4910-fix-for-agent-enabled.yml diff --git a/changelogs/fragments/4910-fix-for-agent-enabled.yml b/changelogs/fragments/4910-fix-for-agent-enabled.yml new file mode 100644 index 0000000000..5ceb5a1e8f --- /dev/null +++ b/changelogs/fragments/4910-fix-for-agent-enabled.yml @@ -0,0 +1,2 @@ +bugfixes: + - proxmox inventory plugin - fix crash when ``enabled=1`` is used in agent config string (https://github.com/ansible-collections/community.general/pull/4910). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 1669b23325..a68cac3c88 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -412,12 +412,20 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): properties[parsed_key] = [tag.strip() for tag in stripped_value.split(",")] # 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_value = self._get_agent_network_interfaces(node, vmid, vmtype) - if agent_iface_value: - agent_iface_key = self.to_safe('%s%s' % (key, "_interfaces")) - properties[agent_iface_key] = agent_iface_value + # the rest of the comma separated string is extra config for the agent. + # In some (newer versions of proxmox) instances it can be 'enabled=1'. + if config == 'agent': + agent_enabled = 0 + try: + agent_enabled = int(value.split(',')[0]) + except ValueError: + if value.split(',')[0] == "enabled=1": + agent_enabled = 1 + if agent_enabled: + agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype) + if agent_iface_value: + agent_iface_key = self.to_safe('%s%s' % (key, "_interfaces")) + properties[agent_iface_key] = agent_iface_value if config == 'lxc': out_val = {}