diff options
author | James Cammarata <jimi@sngx.net> | 2015-11-18 19:12:38 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2015-11-18 19:12:38 -0500 |
commit | 3d1255d19009aa084fd2635917916fd9396ea898 (patch) | |
tree | 0e1f8ead9d18a1f4a5e01e15bbf9e5a9104a9f2e | |
parent | 05b542eb8e28b85da22281476fea3b8625b37715 (diff) | |
download | ansible-3d1255d19009aa084fd2635917916fd9396ea898.tar.gz |
Don't update job vars too early when getting loop items in TaskExecutor
Fixes #13113
-rw-r--r-- | lib/ansible/executor/task_executor.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 2dcb5f9631..48ba2f2414 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -153,16 +153,19 @@ class TaskExecutor: and returns the items result. ''' - # create a copy of the job vars here so that we can modify - # them temporarily without changing them too early for other - # parts of the code that might still need a pristine version - #vars_copy = self._job_vars.copy() - vars_copy = self._job_vars - - # now we update them with the play context vars - self._play_context.update_vars(vars_copy) - - templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=vars_copy) + # save the play context variables to a temporary dictionary, + # so that we can modify the job vars without doing a full copy + # and later restore them to avoid modifying things too early + play_context_vars = dict() + self._play_context.update_vars(play_context_vars) + + old_vars = dict() + for k in play_context_vars.keys(): + if k in self._job_vars: + old_vars[k] = self._job_vars[k] + self._job_vars[k] = play_context_vars[k] + + templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=self._job_vars) items = None if self._task.loop: if self._task.loop in self._shared_loader_obj.lookup_loader: @@ -189,6 +192,15 @@ class TaskExecutor: else: raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop) + # now we restore any old job variables that may have been modified, + # and delete them if they were in the play context vars but not in + # the old variables dictionary + for k in play_context_vars.keys(): + if k in old_vars: + self._job_vars[k] = old_vars[k] + else: + del self._job_vars[k] + if items: from ansible.vars.unsafe_proxy import UnsafeProxy for idx, item in enumerate(items): |