From e8d276e689c76b0a972b5907feffb34433058e31 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 15 Mar 2022 12:34:29 +0100 Subject: [PATCH] Proxmox inventory plugin - Fix string to dict conversion (#4349) (#4365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Proxmox inventory plugin - Fix string to dict conversion (#4348) * Re-use the (defined but unused) `plaintext_configs` variable to list configuration entries that should be ignored by the string to dictionary conversion code. At this point, it only contains the `description` string. * Convert to a dictionary if the all substrings obtained by splitting off the initial value with commas contain a `=` character * Limit substring splitting to a single split, so that a substring containing `a=b=c` will generate an `a` entry with value `b=c`. * Added changelog fragment for PR #4349 * Fix changelog fragment for #4349 (cherry picked from commit 3eec63421afda02c488e6e25a4e7661fc46ac705) Co-authored-by: Emmanuel BenoƮt --- .../fragments/4349-proxmox-inventory-dict-facts.yml | 8 ++++++++ plugins/inventory/proxmox.py | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/4349-proxmox-inventory-dict-facts.yml diff --git a/changelogs/fragments/4349-proxmox-inventory-dict-facts.yml b/changelogs/fragments/4349-proxmox-inventory-dict-facts.yml new file mode 100644 index 0000000000..fcf557c3ed --- /dev/null +++ b/changelogs/fragments/4349-proxmox-inventory-dict-facts.yml @@ -0,0 +1,8 @@ +--- +bugfixes: + - proxmox inventory plugin - fixed the ``description`` field being ignored if + it contained a comma + (https://github.com/ansible-collections/community.general/issues/4348). + - proxmox inventory plugin - always convert strings that follow the + ``key=value[,key=value[...]]`` form into dictionaries + (https://github.com/ansible-collections/community.general/pull/4349). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index f18a058382..a49534874c 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -307,7 +307,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): self.inventory.set_variable(name, vmtype_key, vmtype) plaintext_configs = [ - 'tags', + 'description', ] for config in ret: @@ -333,11 +333,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): if agent_iface_value: self.inventory.set_variable(name, agent_iface_key, agent_iface_value) - if not (isinstance(value, int) or ',' not in value): + if config not in plaintext_configs and not isinstance(value, int) and all("=" in v for v in value.split(",")): # split off strings with commas to a dict # skip over any keys that cannot be processed try: - value = dict(key.split("=") for key in value.split(",")) + value = dict(key.split("=", 1) for key in value.split(",")) except Exception: continue