Skip to content

Commit

Permalink
proxmox inventory: fix for agent enabled (ansible-collections#4910)
Browse files Browse the repository at this point in the history
* 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 <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
2 people authored and Dušan Markovič committed Nov 7, 2022
1 parent af7e486 commit bcdc249
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/4910-fix-for-agent-enabled.yml
Original file line number Diff line number Diff line change
@@ -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).
20 changes: 14 additions & 6 deletions plugins/inventory/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 = {}
Expand Down

0 comments on commit bcdc249

Please sign in to comment.