From bf8ada0eb505dfe7fb53fd979f1dc856343eeb83 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 4 Mar 2019 22:18:57 +0530 Subject: [PATCH] VMware: Fail when unable to find managed object (#53158) Fixes: #52119 Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/cloud/vmware/vmware_tag_manager.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py b/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py index 76009fdc4e..828e5297ff 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py +++ b/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py @@ -126,14 +126,19 @@ class VmwareTagManager(VmwareRestClient): self.object_type = self.params.get('object_type') self.object_name = self.params.get('object_name') + self.managed_object = None if self.object_type == 'VirtualMachine': self.managed_object = self.pyv.get_vm_or_template(self.object_name) - self.dynamic_managed_object = DynamicID(type=self.object_type, id=self.managed_object._moId) if self.managed_object is None: self.module.fail_json(msg="Failed to find the managed object for %s with type %s" % (self.object_name, self.object_type)) + if not hasattr(self.managed_object, '_moId'): + self.module.fail_json(msg="Unable to find managed object id for %s managed object" % self.object_name) + + self.dynamic_managed_object = DynamicID(type=self.object_type, id=self.managed_object._moId) + self.tag_service = Tag(self.connect) self.category_service = Category(self.connect) self.tag_association_svc = TagAssociation(self.connect)