diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index d4d13681b47..f8f5b1cf16c 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -449,16 +449,16 @@ class PyVmomiCache(object): result = find_obj(content, types, name) if result and confine_to_datacenter: if self.get_parent_datacenter(result).name != self.dc_name: + result = None objects = self.get_all_objs(content, types, confine_to_datacenter=True) for obj in objects: - if obj.name == name: + if name is None or obj.name == name: return obj - return result def get_all_objs(self, content, types, confine_to_datacenter=True): """ Wrapper around get_all_objs to set datacenter context """ - objects = get_all_objs(content, [vim.Datastore]) + objects = get_all_objs(content, types) if confine_to_datacenter: if hasattr(objects, 'items'): # resource pools come back as a dictionary diff --git a/test/integration/targets/vmware_guest/tasks/main.yml b/test/integration/targets/vmware_guest/tasks/main.yml index 95d3a4fed42..16a812151b1 100644 --- a/test/integration/targets/vmware_guest/tasks/main.yml +++ b/test/integration/targets/vmware_guest/tasks/main.yml @@ -1,7 +1,7 @@ -#- name: make sure pyvmomi is installed -# pip: -# name: pyvmomi -# state: latest +- name: make sure pyvmomi is installed + pip: + name: pyvmomi + state: latest - name: store the vcenter container ip set_fact: