From 8774ff5f57fdad47d761adff2f2220737446db46 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 3 Sep 2015 08:11:30 -0400 Subject: [PATCH] Make sure PlayContext is copied when iterating in a with_ loop --- lib/ansible/executor/task_executor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 35fe8329eee..1c6346d94ac 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -188,15 +188,18 @@ class TaskExecutor: try: tmp_task = self._task.copy() + tmp_play_context = self._play_context.copy() except AnsibleParserError as e: results.append(dict(failed=True, msg=str(e))) continue - # now we swap the internal task with the copy, execute, - # and swap them back so we can do the next iteration cleanly + # now we swap the internal task and play context with their copies, + # execute, and swap them back so we can do the next iteration cleanly (self._task, tmp_task) = (tmp_task, self._task) + (self._play_context, tmp_play_context) = (tmp_play_context, self._play_context) res = self._execute(variables=task_vars) (self._task, tmp_task) = (tmp_task, self._task) + (self._play_context, tmp_play_context) = (tmp_play_context, self._play_context) # now update the result with the item info, and append the result # to the list of results