From 7035d14d80d981b76bad52ed7ece966e4dc2f9c3 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 04:46:57 +0000 Subject: [PATCH] [PR #12361/bbf8bb47 backport][stable-12] OpenNebula inventory fails if VM without NIC exists (#12365) OpenNebula inventory fails if VM without NIC exists (#12361) * fix error of opennebula plugin when retrieving VM without NIC * add changelog fragment * added more descriptive name, added link to PR --------- (cherry picked from commit bbf8bb47d91aca4bc4293c474d7562e2b96dd70a) Co-authored-by: Simon <4375225+skropf@users.noreply.github.com> Co-authored-by: Felix Fontein --- changelogs/fragments/fix-opennebula_vm_without_nic.yml | 2 ++ plugins/inventory/opennebula.py | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 changelogs/fragments/fix-opennebula_vm_without_nic.yml diff --git a/changelogs/fragments/fix-opennebula_vm_without_nic.yml b/changelogs/fragments/fix-opennebula_vm_without_nic.yml new file mode 100644 index 0000000000..c498035fbb --- /dev/null +++ b/changelogs/fragments/fix-opennebula_vm_without_nic.yml @@ -0,0 +1,2 @@ +bugfixes: + - opennebula inventory plugin - fix crash when retrieving VM without NIC (https://github.com/ansible-collections/community.general/pull/12361). diff --git a/plugins/inventory/opennebula.py b/plugins/inventory/opennebula.py index 2421d55dbc..4b06c57d56 100644 --- a/plugins/inventory/opennebula.py +++ b/plugins/inventory/opennebula.py @@ -133,6 +133,9 @@ class InventoryModule(BaseInventoryPlugin, Constructable): def _get_vm_ipv4(self, vm): nic = vm.TEMPLATE.get("NIC") + if not nic: + return False + if isinstance(nic, dict): nic = [nic] @@ -145,6 +148,9 @@ class InventoryModule(BaseInventoryPlugin, Constructable): def _get_vm_ipv6(self, vm): nic = vm.TEMPLATE.get("NIC") + if not nic: + return False + if isinstance(nic, dict): nic = [nic]