From 518af70b77b27e00c4dda2385df366ef15545edb Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 24 Mar 2022 06:44:02 +0000 Subject: [PATCH] Proxmox inventory plugin - Fix tags parsing (#4378) (#4402) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Proxmox inventory plugin - Fix tags parsing * In some cases the Proxmox API returns a tags string that consists in a single space. The Proxmox inventory plugin parsed that into a single, empty tag. Stripping the initial string then checking whether it actually contains something fixes that. * Do not call `_to_safe` on the concatenation of a known safe string and a string that was already made safe. * Changelog fragment for Proxmox inventory plugin tags fix * Proxmox inventory plugin - Include link to PR in fragment Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit 622895fb55e12408f4cd514e445b0fc1a7b0ebd5) Co-authored-by: Emmanuel BenoƮt --- changelogs/fragments/4378-proxmox-inventory-tags.yml | 4 ++++ plugins/inventory/proxmox.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/4378-proxmox-inventory-tags.yml diff --git a/changelogs/fragments/4378-proxmox-inventory-tags.yml b/changelogs/fragments/4378-proxmox-inventory-tags.yml new file mode 100644 index 0000000000..04110977d5 --- /dev/null +++ b/changelogs/fragments/4378-proxmox-inventory-tags.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - proxmox inventory plugin - fixed the ``tags_parsed`` field when Proxmox + returns a single space for the ``tags`` entry (https://github.com/ansible-collections/community.general/pull/4378). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index fc56297490..f2dba5309b 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -323,8 +323,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): # Additional field containing parsed tags as list if config == 'tags': - parsed_key = self.to_safe('%s%s' % (key, "_parsed")) - properties[parsed_key] = [tag.strip() for tag in value.split(",")] + stripped_value = value.strip() + if stripped_value: + parsed_key = key + "_parsed" + 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