diff --git a/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py b/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py index 48f4b852485..7d327708ca8 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py +++ b/lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py @@ -217,12 +217,10 @@ 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(): + for k, v in tuple(objects.items()): parent_dc = get_parent_datacenter(k) if parent_dc.name != self.dc_name: - tmpobjs.pop(k, None) - objects = tmpobjs + del objects[k] else: # everything else should be a list objects = [x for x in objects if get_parent_datacenter(x).name == self.dc_name] diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index ea71b9329ae..47312f3cf04 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -785,12 +785,10 @@ class PyVmomiCache(object): if hasattr(objects, 'items'): # resource pools come back as a dictionary # make a copy - tmpobjs = objects.copy() - for k, v in objects.items(): + for k, v in tuple(objects.items()): parent_dc = self.get_parent_datacenter(k) if parent_dc.name != self.dc_name: - tmpobjs.pop(k, None) - objects = tmpobjs + del objects[k] else: # everything else should be a list objects = [x for x in objects if self.get_parent_datacenter(x).name == self.dc_name]