From dfb8d0fd1e63aa1916c0bfb3cbafe4c6521f7c6f Mon Sep 17 00:00:00 2001 From: ube Date: Thu, 30 Jun 2022 09:46:37 +0200 Subject: [PATCH 1/8] Update proxmox.py --- plugins/inventory/proxmox.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 1669b233257..954b59e9da2 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -412,12 +412,20 @@ def _get_vm_config(self, properties, node, vmid, vmtype, name): 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 + if value.split(',')[0].isnumeric(): + agent_enabled=int(value.split(',')[0]) + if value.split(',') == "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")) + print ("%s: %s" % (agent_iface_key, agent_iface_value)) + properties[agent_iface_key] = agent_iface_value if config == 'lxc': out_val = {} From 441b2e060e0bf9dcbe7401a176f8669a3103b856 Mon Sep 17 00:00:00 2001 From: ube Date: Thu, 30 Jun 2022 09:51:17 +0200 Subject: [PATCH 2/8] Forgot a debug print. --- plugins/inventory/proxmox.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 954b59e9da2..bd0d903cc16 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -424,7 +424,6 @@ def _get_vm_config(self, properties, node, vmid, vmtype, name): 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")) - print ("%s: %s" % (agent_iface_key, agent_iface_value)) properties[agent_iface_key] = agent_iface_value if config == 'lxc': From df64f107b61aa59fcc6f9865300dfe4e5290d99d Mon Sep 17 00:00:00 2001 From: ube Date: Thu, 30 Jun 2022 10:20:35 +0200 Subject: [PATCH 3/8] pep --- plugins/inventory/proxmox.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index bd0d903cc16..413326aec83 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -415,11 +415,11 @@ def _get_vm_config(self, properties, node, vmid, vmtype, name): # 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 + agent_enabled = 0 if value.split(',')[0].isnumeric(): - agent_enabled=int(value.split(',')[0]) - if value.split(',') == "enabled=1": - agent_enabled=1 + agent_enabled = int(value.split(',')[0]) + if value.split(',') == "enabled=1": + agent_enabled = 1 if agent_enabled: agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype) if agent_iface_value: From c094f36e37cdf8e293a527d417ab3822781c98d0 Mon Sep 17 00:00:00 2001 From: ube Date: Thu, 30 Jun 2022 11:07:08 +0200 Subject: [PATCH 4/8] Check if int, old school way. --- plugins/inventory/proxmox.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 413326aec83..637cc669133 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -416,10 +416,11 @@ def _get_vm_config(self, properties, node, vmid, vmtype, name): # In some (newer versions of proxmox) instances it can be 'enabled=1'. if config == 'agent': agent_enabled = 0 - if value.split(',')[0].isnumeric(): + try: agent_enabled = int(value.split(',')[0]) - if value.split(',') == "enabled=1": - agent_enabled = 1 + except ValueError: + if value.split(',') == "enabled=1": + agent_enabled = 1 if agent_enabled: agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype) if agent_iface_value: From 4e094cd8041fd7a45b712aa91e401fc7065688a7 Mon Sep 17 00:00:00 2001 From: ube Date: Thu, 30 Jun 2022 12:34:57 +0200 Subject: [PATCH 5/8] pep, once again. --- plugins/inventory/proxmox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 637cc669133..9d0384cf430 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -419,7 +419,7 @@ def _get_vm_config(self, properties, node, vmid, vmtype, name): try: agent_enabled = int(value.split(',')[0]) except ValueError: - if value.split(',') == "enabled=1": + if value.split(',') == "enabled=1": agent_enabled = 1 if agent_enabled: agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype) From 81b2ed7e091562edc86fbdd02a9b691ef33125d3 Mon Sep 17 00:00:00 2001 From: ube Date: Mon, 4 Jul 2022 08:29:52 +0200 Subject: [PATCH 6/8] Create 4910-fix-for-agent-enabled.yml --- changelogs/fragments/4910-fix-for-agent-enabled.yml | 2 ++ 1 file changed, 2 insertions(+) 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 00000000000..868ec6adb6f --- /dev/null +++ b/changelogs/fragments/4910-fix-for-agent-enabled.yml @@ -0,0 +1,2 @@ +bugfixes: + - proxmox - fix invenetory plugin crash when "enabled=1" is used in agent config string. From c62718c9a869afd481c71651bf8875ee4bcb1571 Mon Sep 17 00:00:00 2001 From: ube Date: Mon, 4 Jul 2022 14:00:34 +0200 Subject: [PATCH 7/8] Must check the first listentry for enabled=1 --- plugins/inventory/proxmox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 9d0384cf430..a68cac3c887 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -419,7 +419,7 @@ def _get_vm_config(self, properties, node, vmid, vmtype, name): try: agent_enabled = int(value.split(',')[0]) except ValueError: - if value.split(',') == "enabled=1": + if value.split(',')[0] == "enabled=1": agent_enabled = 1 if agent_enabled: agent_iface_value = self._get_agent_network_interfaces(node, vmid, vmtype) From 5a8296966cd7c8ef2fa7d5746507e98530658c7d Mon Sep 17 00:00:00 2001 From: ube Date: Tue, 5 Jul 2022 09:48:26 +0200 Subject: [PATCH 8/8] Update changelogs/fragments/4910-fix-for-agent-enabled.yml Co-authored-by: Felix Fontein --- changelogs/fragments/4910-fix-for-agent-enabled.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/4910-fix-for-agent-enabled.yml b/changelogs/fragments/4910-fix-for-agent-enabled.yml index 868ec6adb6f..5ceb5a1e8fc 100644 --- a/changelogs/fragments/4910-fix-for-agent-enabled.yml +++ b/changelogs/fragments/4910-fix-for-agent-enabled.yml @@ -1,2 +1,2 @@ bugfixes: - - proxmox - fix invenetory plugin crash when "enabled=1" is used in agent config string. + - proxmox inventory plugin - fix crash when ``enabled=1`` is used in agent config string (https://github.com/ansible-collections/community.general/pull/4910).