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]