Fix storing local task_vars facts for the retry (#70171)

* Fix storing local task_vars facts for the retry

Fixes #70168
This commit is contained in:
Martin Krizek 2020-06-22 16:07:47 +02:00 committed by GitHub
parent b2d6db7916
commit eaf6086eea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "Fix ``delegate_facts: true`` when ``ansible_python_interpreter`` is not set. (https://github.com/ansible/ansible/issues/70168)"

View file

@ -160,7 +160,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
''' '''
if task_vars is None: if task_vars is None:
use_vars = dict() task_vars = {}
if self._task.delegate_to: if self._task.delegate_to:
use_vars = task_vars.get('ansible_delegated_vars')[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: 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 # 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: if use_vars.get('ansible_facts') is None:
task_vars['ansible_facts'] = {} task_vars['ansible_facts'] = use_vars['ansible_facts'] = {}
task_vars['ansible_facts'][discovered_key] = self._discovered_interpreter 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 # preserve this so _execute_module can propagate back to controller as a fact
self._discovered_interpreter_key = discovered_key self._discovered_interpreter_key = discovered_key
else: 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: 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'] = {}
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 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) return (module_style, module_shebang, module_data, module_path)

View file

@ -2,3 +2,4 @@ shippable/posix/group3
needs/ssh needs/ssh
needs/root # only on macOS and FreeBSD to configure network interfaces needs/root # only on macOS and FreeBSD to configure network interfaces
skip/aix skip/aix
non_local # workaround to allow override of ansible_python_interpreter; disables coverage on this integration target

View file

@ -70,3 +70,6 @@ ln -s python secondpython
) )
ansible-playbook verify_interpreter.yml -i inventory_interpreters -v "$@" ansible-playbook verify_interpreter.yml -i inventory_interpreters -v "$@"
ansible-playbook discovery_applied.yml -i inventory -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 "$@"

View file

@ -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