From 1010363c0bebaf4ef3c34ac858d74de5ca01fc7b Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 24 Jul 2019 11:35:14 +0200 Subject: [PATCH] Preserve original variables when using a loop (#59426) Fixes #59414 --- lib/ansible/executor/task_executor.py | 2 +- test/integration/targets/loops/tasks/main.yml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 6aee5ba845a..5782c93c83b 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -423,7 +423,7 @@ class TaskExecutor: 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 diff --git a/test/integration/targets/loops/tasks/main.yml b/test/integration/targets/loops/tasks/main.yml index 0ce32ab589e..5dd7d26fe95 100644 --- a/test/integration/targets/loops/tasks/main.yml +++ b/test/integration/targets/loops/tasks/main.yml @@ -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'