Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve original variables when using a loop #59417

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions lib/ansible/executor/task_executor.py
Expand Up @@ -412,20 +412,6 @@ def _run_loop(self, items):
results.append(res)
del task_vars[loop_var]

# clear 'connection related' plugin variables for next iteration
if self._connection:
clear_plugins = {
'connection': self._connection._load_name,
'shell': self._connection._shell._load_name
}
if self._connection.become:
clear_plugins['become'] = self._connection.become._load_name

for plugin_type, plugin_name in iteritems(clear_plugins):
for var in C.config.get_plugin_vars(plugin_type, plugin_name):
if var in task_vars:
del task_vars[var]

self._task.no_log = no_log

return results
Expand Down Expand Up @@ -524,6 +510,11 @@ def _execute(self, variables=None):
if variables is None:
variables = self._job_vars

# the code below can modify the variables, take a copy so future loop
# iterations are not tainted by "magic" variables that are a result of
# the loops item.
variables = variables.copy()

templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=variables)

context_validation_error = None
Expand Down