loop/fact delegation fix (#75768)

now set_fact and include_vars intermediate results are congruent with delegation
pull/76194/head
Brian Coca 4 years ago committed by GitHub
parent 8bbecc7cac
commit 7bec196061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- set_fact/include_vars correctly handle delegation assignments within loops

@ -654,7 +654,13 @@ class TaskExecutor:
if 'ansible_facts' in result and self._task.action not in C._ACTION_DEBUG:
if self._task.action in C._ACTION_WITH_CLEAN_FACTS:
vars_copy.update(result['ansible_facts'])
if self._task.delegate_to and self._task.delegate_facts:
if '_ansible_delegated_vars' in vars_copy:
vars_copy['_ansible_delegated_vars'].update(result['ansible_facts'])
else:
vars_copy['_ansible_delegated_vars'] = result['ansible_facts']
else:
vars_copy.update(result['ansible_facts'])
else:
# TODO: cleaning of facts should eventually become part of taskresults instead of vars
af = wrap_var(result['ansible_facts'])
@ -738,7 +744,13 @@ class TaskExecutor:
if 'ansible_facts' in result and self._task.action not in C._ACTION_DEBUG:
if self._task.action in C._ACTION_WITH_CLEAN_FACTS:
variables.update(result['ansible_facts'])
if self._task.delegate_to and self._task.delegate_facts:
if '_ansible_delegated_vars' in variables:
variables['_ansible_delegated_vars'].update(result['ansible_facts'])
else:
variables['_ansible_delegated_vars'] = result['ansible_facts']
else:
variables.update(result['ansible_facts'])
else:
# TODO: cleaning of facts should eventually become part of taskresults instead of vars
af = wrap_var(result['ansible_facts'])

@ -0,0 +1,21 @@
- hosts: localhost
gather_facts: no
tasks:
- set_fact:
test: 123
delegate_to: "{{ item }}"
delegate_facts: true
when: test is not defined
loop: "{{ groups['all'] | difference(['localhost']) }}"
- name: ensure we didnt create it on current host
assert:
that:
- test is undefined
- name: ensure facts get created
assert:
that:
- "'test' in hostvars[item]"
- hostvars[item]['test'] == 123
loop: "{{ groups['all'] | difference(['localhost']) }}"

@ -75,3 +75,4 @@ ansible-playbook resolve_vars.yml -i inventory -v "$@"
ansible-playbook test_delegate_to_lookup_context.yml -i inventory -v "$@"
ansible-playbook delegate_local_from_root.yml -i inventory -v "$@" -e 'ansible_user=root'
ansible-playbook delegate_with_fact_from_delegate_host.yml "$@"
ansible-playbook delegate_facts_loop.yml -i inventory -v "$@"

Loading…
Cancel
Save