cast/copy keys() to list to avoid py3 errors

In py3, dict.keys() is a view and not a copy of the
dicts keys, so attempting to delete items from the dict
while iterating over the keys results int

RuntimeError: dictionary changed size during iteration

Resolve by casting .keys() to a list() type.

(cherry picked from commit 2addc09050)
This commit is contained in:
Adrian Likins 2016-10-03 10:46:24 -04:00 committed by Toshio Kuratomi
parent f4b1d87ec0
commit 5109d50adb

View file

@ -114,7 +114,7 @@ class ActionModule(ActionBase):
# connection to the remote host
if 'ansible_syslog_facility' in task_vars:
del task_vars['ansible_syslog_facility']
for key in task_vars.keys():
for key in list(task_vars.keys()):
if key.startswith("ansible_") and key.endswith("_interpreter"):
del task_vars[key]