Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tags strings containing commas in proxmox inventory plug-in #1949

Merged
merged 10 commits into from
Mar 11, 2021
5 changes: 5 additions & 0 deletions changelogs/fragments/1949-proxmox-inventory-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
bugfixes:
- proxmox inventory plugin - allowed proxomox tag string to contain commas when returned as fact (https://github.com/ansible-collections/community.general/pull/1949).
minor_changes:
- proxmox inventory plugin - added ``tags_parsed`` fact containing tags parsed as a list (https://github.com/ansible-collections/community.general/pull/1949).
10 changes: 10 additions & 0 deletions plugins/inventory/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def _get_vm_config(self, node, vmid, vmtype, name):
vmtype_key = self.to_safe('%s%s' % (self.get_option('facts_prefix'), vmtype_key.lower()))
self.inventory.set_variable(name, vmtype_key, vmtype)

plaintext_configs = [
'tags',
]

for config in ret:
key = config
key = self.to_safe('%s%s' % (self.get_option('facts_prefix'), key.lower()))
Expand All @@ -226,6 +230,12 @@ def _get_vm_config(self, node, vmid, vmtype, name):
if config == 'rootfs' or config.startswith(('virtio', 'sata', 'ide', 'scsi')):
value = ('disk_image=' + value)

# Additional field containing parsed tags as list
if config == 'tags':
parsed_key = self.to_safe('%s%s' % (key, "_parsed"))
parsed_value = [tag.strip() for tag in value.split(",")]
self.inventory.set_variable(name, parsed_key, parsed_value)

if not (isinstance(value, int) or ',' not in value):
# split off strings with commas to a dict
# skip over any keys that cannot be processed
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/plugins/inventory/test_proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def get_json(url):
"status": "running",
"vmid": "100",
"disk": "1000",
"uptime": 1000}]
"uptime": 1000,
"tags": "test, tags, here"}]
elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu":
# _get_qemu_per_node
return [{"name": "test-qemu",
Expand Down Expand Up @@ -105,7 +106,8 @@ def get_json(url):
"vmid": "9001",
"uptime": 0,
"disk": 0,
"status": "stopped"}]
"status": "stopped",
"tags": "test, tags, here"}]
elif url == "https://localhost:8006/api2/json/pools/test":
# _get_members_per_pool
return {"members": [{"uptime": 1000,
Expand Down