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 v2 #59426

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/ansible/executor/task_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def _run_loop(self, items):

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:
if var in task_vars and var not in self._job_vars:
del task_vars[var]

self._task.no_log = no_log
Expand Down
15 changes: 15 additions & 0 deletions test/integration/targets/loops/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,18 @@
loop_var: "{{ loop_var_name }}"
vars:
loop_var_name: templated_loop_var_name

# https://github.com/ansible/ansible/issues/59414
- name: Test preserving original connection related vars
debug:
var: ansible_remote_tmp
vars:
ansible_remote_tmp: /tmp/test1
with_items:
- 1
- 2
register: loop_out

- assert:
that:
- loop_out['results'][1]['ansible_remote_tmp'] == '/tmp/test1'