From 4c9d9dbb56273c632d391a355fdb35504cc92be3 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 11 Jun 2020 18:04:17 -0400 Subject: [PATCH] fix discovery on loop with delegation (#70013) * fix discovery on loop with delegation fixes #69963 --- changelogs/fragments/ensure_discovery_delegate.yml | 2 ++ lib/ansible/plugins/action/__init__.py | 5 +++++ .../integration/targets/delegate_to/discovery_applied.yml | 8 ++++++++ test/integration/targets/delegate_to/runme.sh | 1 + 4 files changed, 16 insertions(+) create mode 100644 changelogs/fragments/ensure_discovery_delegate.yml create mode 100644 test/integration/targets/delegate_to/discovery_applied.yml diff --git a/changelogs/fragments/ensure_discovery_delegate.yml b/changelogs/fragments/ensure_discovery_delegate.yml new file mode 100644 index 00000000000..37daad1b8a5 --- /dev/null +++ b/changelogs/fragments/ensure_discovery_delegate.yml @@ -0,0 +1,2 @@ +bugfixes: + - ensure we pass on interpreter discovery values to delegated host. diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 0a1f60dd69e..83c7715d3ee 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -252,6 +252,11 @@ class ActionBase(with_metaclass(ABCMeta, object)): task_vars['ansible_facts'][discovered_key] = self._discovered_interpreter # preserve this so _execute_module can propagate back to controller as a fact self._discovered_interpreter_key = discovered_key + else: + task_vars['ansible_delegated_vars'][self._task.delegate_to] + if task_vars['ansible_delegated_vars'][self._task.delegate_to].get('ansible_facts') is None: + task_vars['ansible_delegated_vars'][self._task.delegate_to]['ansible_facts'] = {} + task_vars['ansible_delegated_vars'][self._task.delegate_to]['ansible_facts'][discovered_key] = self._discovered_interpreter return (module_style, module_shebang, module_data, module_path) diff --git a/test/integration/targets/delegate_to/discovery_applied.yml b/test/integration/targets/delegate_to/discovery_applied.yml new file mode 100644 index 00000000000..fafe664c946 --- /dev/null +++ b/test/integration/targets/delegate_to/discovery_applied.yml @@ -0,0 +1,8 @@ +- hosts: testhost + gather_facts: no + tasks: + - command: ls + delegate_to: "{{ item }}" + with_items: + - localhost + - "{{ inventory_hostname }}" diff --git a/test/integration/targets/delegate_to/runme.sh b/test/integration/targets/delegate_to/runme.sh index 730d5cc9c74..8095c921d23 100755 --- a/test/integration/targets/delegate_to/runme.sh +++ b/test/integration/targets/delegate_to/runme.sh @@ -69,3 +69,4 @@ ln -s python firstpython ln -s python secondpython ) ansible-playbook verify_interpreter.yml -i inventory_interpreters -v "$@" +ansible-playbook discovery_applied.yml -i inventory -v "$@"