From e9c9c02e0a8deaa8382ba6393c7a5ca09b13167d Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Fri, 24 Jul 2020 10:48:45 +1000 Subject: [PATCH] Do not add connection vars to the output results (#70853) (#70855) * Do not add connection vars to the output results * Also revert the delgated scenario JIC * Added regression test (cherry picked from commit 5e1a9689837d404fd9d2db3429acf499cf1a3d2b) --- changelogs/fragments/set_fact-connection_vars.yml | 2 ++ lib/ansible/executor/task_executor.py | 9 ++------- test/integration/targets/connection/test.sh | 13 +++++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/set_fact-connection_vars.yml diff --git a/changelogs/fragments/set_fact-connection_vars.yml b/changelogs/fragments/set_fact-connection_vars.yml new file mode 100644 index 00000000000..0dd2ac43ed9 --- /dev/null +++ b/changelogs/fragments/set_fact-connection_vars.yml @@ -0,0 +1,2 @@ +bugfixes: +- Stop adding the connection variables to the output results diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index bd44f10ec2c..63b1a7b4cad 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -798,13 +798,8 @@ class TaskExecutor: # also now add conneciton vars results when delegating if self._task.delegate_to: result["_ansible_delegated_vars"] = {'ansible_delegated_host': self._task.delegate_to} - for k in plugin_vars + RETURN_VARS: - if k in cvars and cvars[k] is not None: - result["_ansible_delegated_vars"][k] = cvars[k] - else: - for k in plugin_vars + RETURN_VARS: - if k in cvars and cvars[k] is not None: - result[k] = cvars[k] + for k in plugin_vars: + result["_ansible_delegated_vars"][k] = cvars.get(k) # and return display.debug("attempt loop complete, returning result") diff --git a/test/integration/targets/connection/test.sh b/test/integration/targets/connection/test.sh index 4e7aa8dda13..18fb2b776f0 100755 --- a/test/integration/targets/connection/test.sh +++ b/test/integration/targets/connection/test.sh @@ -8,3 +8,16 @@ set -eux ansible-playbook test_connection.yml -i "${INVENTORY}" "$@" LC_ALL=C LANG=C ansible-playbook test_connection.yml -i "${INVENTORY}" "$@" + +# Check that connection vars do not appear in the output +# https://github.com/ansible/ansible/pull/70853 +trap "rm out.txt" EXIT + +ansible all -i "${INVENTORY}" -m set_fact -a "testing=value" -v | tee out.txt +if grep 'ansible_host' out.txt +then + echo "FAILURE: Connection vars in output" + exit 1 +else + echo "SUCCESS: Connection vars not found" +fi