Skip to content

Commit

Permalink
Fix storing local task_vars facts for the retry (ansible#70171)
Browse files Browse the repository at this point in the history
Fixes ansible#70168

(cherry picked from commit eaf6086)
  • Loading branch information
mkrizek committed Jun 22, 2020
1 parent cd7dfce commit 425fd5d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "Fix ``delegate_facts: true`` when ``ansible_python_interpreter`` is not set. (https://github.com/ansible/ansible/issues/70168)"
9 changes: 5 additions & 4 deletions lib/ansible/plugins/action/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _configure_module(self, module_name, module_args, task_vars=None):
'''

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]
Expand Down Expand Up @@ -231,15 +231,16 @@ def _configure_module(self, module_name, module_args, task_vars=None):
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)

Expand Down
1 change: 1 addition & 0 deletions test/integration/targets/delegate_to/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
shippable/posix/group3
needs/ssh
needs/root # only on macOS and FreeBSD to configure network interfaces
non_local # workaround to allow override of ansible_python_interpreter; disables coverage on this integration target
3 changes: 3 additions & 0 deletions test/integration/targets/delegate_to/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 425fd5d

Please sign in to comment.