diff --git a/changelogs/fragments/4351-inventory-lxd-handling_metadata_wo_os_and_release.yml b/changelogs/fragments/4351-inventory-lxd-handling_metadata_wo_os_and_release.yml new file mode 100644 index 0000000000..f7541a7a61 --- /dev/null +++ b/changelogs/fragments/4351-inventory-lxd-handling_metadata_wo_os_and_release.yml @@ -0,0 +1,4 @@ +bugfixes: + - | + lxd inventory plugin - do not crash if OS and release metadata are not present + (https://github.com/ansible-collections/community.general/pull/4351). diff --git a/plugins/inventory/lxd.py b/plugins/inventory/lxd.py index cdb0fa19b1..912638509d 100644 --- a/plugins/inventory/lxd.py +++ b/plugins/inventory/lxd.py @@ -666,9 +666,13 @@ class InventoryModule(BaseInventoryPlugin): # add network informations self.build_inventory_network(instance_name) # add os - self.inventory.set_variable(instance_name, 'ansible_lxd_os', self._get_data_entry('inventory/{0}/os'.format(instance_name)).lower()) + v = self._get_data_entry('inventory/{0}/os'.format(instance_name)) + if v: + self.inventory.set_variable(instance_name, 'ansible_lxd_os', v.lower()) # add release - self.inventory.set_variable(instance_name, 'ansible_lxd_release', self._get_data_entry('inventory/{0}/release'.format(instance_name)).lower()) + v = self._get_data_entry('inventory/{0}/release'.format(instance_name)) + if v: + self.inventory.set_variable(instance_name, 'ansible_lxd_release', v.lower()) # add profile self.inventory.set_variable(instance_name, 'ansible_lxd_profile', self._get_data_entry('inventory/{0}/profile'.format(instance_name))) # add state