From 7a5e7c83d33267cf14017377b5a08b6d5a71910d Mon Sep 17 00:00:00 2001 From: Megian Date: Tue, 3 Apr 2018 12:13:09 +0200 Subject: [PATCH] dictionary changed size during iteration error (#37454) Iterating an object and changing it at the same time is unsecure and no longer permitted in Python >= 3.6 Provisioning an instance fail with the Python error: "RuntimeError: dictionary changed size during iteration" --- lib/ansible/modules/cloud/cloudscale/cloudscale_server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py b/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py index 1763dd58d8..63248d7b2e 100644 --- a/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py +++ b/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py @@ -205,6 +205,7 @@ anti_affinity_with: import os from datetime import datetime, timedelta from time import sleep +from copy import deepcopy from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.cloudscale import AnsibleCloudscaleBase, cloudscale_argument_spec @@ -296,8 +297,11 @@ class AnsibleCloudscaleServer(AnsibleCloudscaleBase): self._module.fail_json(msg='Missing required parameter(s) to create a new server: %s.' % ' '.join(missing_parameters)) + # Deepcopy: Duplicate the data object for iteration, because + # iterating an object and changing it at the same time is insecure + # Sanitize data dictionary - for k, v in data.items(): + for k, v in deepcopy(data).items(): # Remove items not relevant to the create server call if k in ('api_token', 'api_timeout', 'uuid', 'state'):