From 198e27753197752a5728f29e1543c55a4165ac57 Mon Sep 17 00:00:00 2001 From: Pascal Mathis Date: Thu, 24 Oct 2024 08:57:32 +0200 Subject: [PATCH] vmware_guest: Fix vApp property handling The vmware_guest module did not properly handle setting vApp properties if the VmConfigSpec never contained an active vAppConfig. This resulted in an exception due to trying to access `property` on `None`. This commit changes the behavior to default the current list of vApp properties to an empty list if there has never been any vAppConfig. --- changelogs/fragments/2220-vmware_guest.yml | 4 ++++ plugins/modules/vmware_guest.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/2220-vmware_guest.yml diff --git a/changelogs/fragments/2220-vmware_guest.yml b/changelogs/fragments/2220-vmware_guest.yml new file mode 100644 index 000000000..0a13b87d4 --- /dev/null +++ b/changelogs/fragments/2220-vmware_guest.yml @@ -0,0 +1,4 @@ +bugfixes: + - vmware_guest - setting vApp properties on virtual machines without vApp options raised an AttributeError. + Fix now gracefully handles a `None` value for vApp options when retrieving current vApp properties + (https://github.com/ansible-collections/community.vmware/pull/2220). diff --git a/plugins/modules/vmware_guest.py b/plugins/modules/vmware_guest.py index 9bf8256d5..2c3dffe62 100644 --- a/plugins/modules/vmware_guest.py +++ b/plugins/modules/vmware_guest.py @@ -2067,13 +2067,14 @@ def configure_vapp_properties(self, vm_obj): if vm_obj: # VM exists orig_spec = vm_obj.config.vAppConfig + orig_properties = orig_spec.property if orig_spec is not None else [] - vapp_properties_current = dict((x.id, x) for x in orig_spec.property) + vapp_properties_current = dict((x.id, x) for x in orig_properties) vapp_properties_to_change = dict((x['id'], x) for x in self.params['vapp_properties']) # each property must have a unique key # init key counter with max value + 1 - all_keys = [x.key for x in orig_spec.property] + all_keys = [x.key for x in orig_properties] new_property_index = max(all_keys) + 1 if all_keys else 0 for property_id, property_spec in vapp_properties_to_change.items():