From eaf6086eeab3ffc0389694a037c776cd3d6ac0b5 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 22 Jun 2020 16:07:47 +0200 Subject: [PATCH] Fix storing local task_vars facts for the retry (#70171) * Fix storing local task_vars facts for the retry Fixes #70168 --- ...168-fix-delegate_facts-without-interpreter-set.yml | 2 ++ lib/ansible/plugins/action/__init__.py | 9 +++++---- test/integration/targets/delegate_to/aliases | 1 + test/integration/targets/delegate_to/runme.sh | 3 +++ .../delegate_to/verify_interpreter_delegate_facts.yml | 11 +++++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/70168-fix-delegate_facts-without-interpreter-set.yml create mode 100644 test/integration/targets/delegate_to/verify_interpreter_delegate_facts.yml diff --git a/changelogs/fragments/70168-fix-delegate_facts-without-interpreter-set.yml b/changelogs/fragments/70168-fix-delegate_facts-without-interpreter-set.yml new file mode 100644 index 00000000000..371778eabb2 --- /dev/null +++ b/changelogs/fragments/70168-fix-delegate_facts-without-interpreter-set.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Fix ``delegate_facts: true`` when ``ansible_python_interpreter`` is not set. (https://github.com/ansible/ansible/issues/70168)" diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 83c7715d3ee..565b27502cd 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -160,7 +160,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): ''' if task_vars is None: - use_vars = dict() + task_vars = {} if self._task.delegate_to: use_vars = task_vars.get('ansible_delegated_vars')[self._task.delegate_to] @@ -248,15 +248,16 @@ class ActionBase(with_metaclass(ABCMeta, object)): if not self._task.delegate_to or self._task.delegate_facts: # store in local task_vars facts collection for the retry and any other usages in this worker if use_vars.get('ansible_facts') is None: - task_vars['ansible_facts'] = {} - task_vars['ansible_facts'][discovered_key] = self._discovered_interpreter + task_vars['ansible_facts'] = use_vars['ansible_facts'] = {} + task_vars['ansible_facts'][discovered_key] = use_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'] = {} + use_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 + use_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/aliases b/test/integration/targets/delegate_to/aliases index b8e973dacea..5ba9106d8ad 100644 --- a/test/integration/targets/delegate_to/aliases +++ b/test/integration/targets/delegate_to/aliases @@ -2,3 +2,4 @@ shippable/posix/group3 needs/ssh needs/root # only on macOS and FreeBSD to configure network interfaces skip/aix +non_local # workaround to allow override of ansible_python_interpreter; disables coverage on this integration target diff --git a/test/integration/targets/delegate_to/runme.sh b/test/integration/targets/delegate_to/runme.sh index 8095c921d23..b315d20ef84 100755 --- a/test/integration/targets/delegate_to/runme.sh +++ b/test/integration/targets/delegate_to/runme.sh @@ -70,3 +70,6 @@ ln -s python secondpython ) ansible-playbook verify_interpreter.yml -i inventory_interpreters -v "$@" ansible-playbook discovery_applied.yml -i inventory -v "$@" + +# https://github.com/ansible/ansible/issues/70168 +ansible-playbook verify_interpreter_delegate_facts.yml -i inventory -v "$@" diff --git a/test/integration/targets/delegate_to/verify_interpreter_delegate_facts.yml b/test/integration/targets/delegate_to/verify_interpreter_delegate_facts.yml new file mode 100644 index 00000000000..27e90ed49c8 --- /dev/null +++ b/test/integration/targets/delegate_to/verify_interpreter_delegate_facts.yml @@ -0,0 +1,11 @@ +- hosts: testhost + gather_facts: yes + tasks: + - detect_interpreter: + delegate_to: "{{ item }}" + delegate_facts: yes + vars: + ansible_python_interpreter: auto + loop: + - testhost3 + - testhost4