Don't update job vars too early when getting loop items in TaskExecutor

Fixes #13113
pull/13214/head
James Cammarata 9 years ago
parent 05b542eb8e
commit 3d1255d190

@ -153,16 +153,19 @@ class TaskExecutor:
and returns the items result. and returns the items result.
''' '''
# create a copy of the job vars here so that we can modify # save the play context variables to a temporary dictionary,
# them temporarily without changing them too early for other # so that we can modify the job vars without doing a full copy
# parts of the code that might still need a pristine version # and later restore them to avoid modifying things too early
#vars_copy = self._job_vars.copy() play_context_vars = dict()
vars_copy = self._job_vars self._play_context.update_vars(play_context_vars)
# now we update them with the play context vars old_vars = dict()
self._play_context.update_vars(vars_copy) for k in play_context_vars.keys():
if k in self._job_vars:
templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=vars_copy) 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 items = None
if self._task.loop: if self._task.loop:
if self._task.loop in self._shared_loader_obj.lookup_loader: if self._task.loop in self._shared_loader_obj.lookup_loader:
@ -189,6 +192,15 @@ class TaskExecutor:
else: else:
raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop) 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: if items:
from ansible.vars.unsafe_proxy import UnsafeProxy from ansible.vars.unsafe_proxy import UnsafeProxy
for idx, item in enumerate(items): for idx, item in enumerate(items):

Loading…
Cancel
Save