From 5eff31e760d39bf45b5aa8be5356356000f545d0 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 16 Jun 2024 22:24:35 +0200 Subject: [PATCH] [PR #8489/3716187f backport][stable-9] Fix OpenNebula inventory crash when NIC does not have IP (#8519) Fix OpenNebula inventory crash when NIC does not have IP (#8489) * Fix OpenNebula inventory crash when NIC does not have IP Match IPv6 behaviour. When a NIC does not have an IP: File "ansible/inventory/manager.py", line 292, in parse_source plugin.parse(self._inventory, self._loader, source, cache=cache) File "ansible-cm/plugins/inventory/opennebula.py", line 263, in parse self._populate() File "ansible-cm/plugins/inventory/opennebula.py", line 226, in _populate servers = self._retrieve_servers(filter_by_label) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "ansible-cm/plugins/inventory/opennebula.py", line 210, in _retrieve_servers server['v4_first_ip'] = self._get_vm_ipv4(vm) ^^^^^^^^^^^^^^^^^^^^^ File "ansible-cm/plugins/inventory/opennebula.py", line 154, in _get_vm_ipv4 return net['IP'] * Update to call to match IPv6 and add changelog fragment * Update changelog fragment. --------- Co-authored-by: Felix Fontein (cherry picked from commit 3716187fc35cb9ea8a0722745124bf2d9399246a) Co-authored-by: Tom Paine --- .../8489-fix-opennebula-inventory-crash-when-nic-has-no-ip.yml | 2 ++ plugins/inventory/opennebula.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/8489-fix-opennebula-inventory-crash-when-nic-has-no-ip.yml diff --git a/changelogs/fragments/8489-fix-opennebula-inventory-crash-when-nic-has-no-ip.yml b/changelogs/fragments/8489-fix-opennebula-inventory-crash-when-nic-has-no-ip.yml new file mode 100644 index 0000000000..3db86f364e --- /dev/null +++ b/changelogs/fragments/8489-fix-opennebula-inventory-crash-when-nic-has-no-ip.yml @@ -0,0 +1,2 @@ +bugfixes: + - opennebula inventory plugin - fix invalid reference to IP when inventory runs against NICs with no IPv4 address (https://github.com/ansible-collections/community.general/pull/8489). diff --git a/plugins/inventory/opennebula.py b/plugins/inventory/opennebula.py index b097307c39..bf81758ef1 100644 --- a/plugins/inventory/opennebula.py +++ b/plugins/inventory/opennebula.py @@ -143,7 +143,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable): nic = [nic] for net in nic: - return net['IP'] + if net.get('IP'): + return net['IP'] return False