From c9c91efdd60ec453ba9ecb5ab20cf8a223187e8f Mon Sep 17 00:00:00 2001 From: "Nikitin, Alexander" Date: Tue, 19 Sep 2023 14:23:47 +0300 Subject: [PATCH] fix issue #1772 --- changelogs/fragments/issue_1772.yml | 3 +++ plugins/modules/vmware_guest_custom_attributes.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/issue_1772.yml 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