diff --git a/changelogs/fragments/issue_1772.yml b/changelogs/fragments/issue_1772.yml new file mode 100644 index 000000000..05c107033 --- /dev/null +++ b/changelogs/fragments/issue_1772.yml @@ -0,0 +1,3 @@ +bugfixes: + - fix problem when module try apply non global or non VM type custom attribute to + VM object (https://github.com/ansible-collections/community.vmware/issues/1772) diff --git a/plugins/modules/vmware_guest_custom_attributes.py b/plugins/modules/vmware_guest_custom_attributes.py index 1677f9ef2..9f66e6cbc 100644 --- a/plugins/modules/vmware_guest_custom_attributes.py +++ b/plugins/modules/vmware_guest_custom_attributes.py @@ -247,7 +247,11 @@ def check_exists(self, vm, user_fields): """ # Gather the available existing custom attributes based on user_fields existing_custom_attributes = [] - for k, n in [(x.key, x.name) for x in self.custom_field_mgr for v in user_fields if x.name == v['name']]: + for k, n in [(x.key, x.name) for x in self.custom_field_mgr + # vmware_guest_custome_attributes must work with self moref type of custom attributes or with global custom attributes + if x.managedObjectType == vim.VirtualMachine or x.managedObjectType is None + for v in user_fields + if x.name == v['name']]: existing_custom_attributes.append({ "key": k, "name": n