diff --git a/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py b/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py index 1fd9ccbcdf2..041b0882942 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py +++ b/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py @@ -214,10 +214,12 @@ class PyVmomiCache(object): if confine_to_datacenter: if hasattr(objects, 'items'): # resource pools come back as a dictionary + tmpobjs = objects.copy() for k, v in objects.items(): parent_dc = get_parent_datacenter(k) if parent_dc.name != self.dc_name: - objects.pop(k, None) + tmpobjs.pop(k, None) + objects = tmpobjs else: # everything else should be a list objects = [x for x in objects if get_parent_datacenter(x).name == self.dc_name]