Fix final fact delegation (#77008)

* fix facts delegation loop overwrite

 partial revert of change to allow facts to be present in each loop iteration
 was not needed in final results as result processing alreayd had the disctiontion
 and ended up breaking the assumptions in the calling code.

 fixes #76676
pull/77018/head^2
Brian Coca 4 years ago committed by GitHub
parent 56edbd2bbb
commit c9d3518d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- task_executor reverts the change to push facts into delegated vars on loop finalization as result managing code already handles this and was duplicating effort to wrong result.

@ -786,13 +786,7 @@ 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:
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'])
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'])

@ -5,7 +5,6 @@
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
@ -19,3 +18,23 @@
- "'test' in hostvars[item]"
- hostvars[item]['test'] == 123
loop: "{{ groups['all'] | difference(['localhost'])}}"
- name: test that we don't polute whole group with one value
hosts: localhost
gather_facts: no
vars:
cluster_name: bleh
tasks:
- name: construct different fact per host in loop
set_fact:
vm_name: "{{ cluster_name }}-{{item}}"
delegate_to: "{{ item }}"
delegate_facts: True
with_items: "{{ groups['all'] }}"
- name: ensure the fact is personalized for each host
assert:
that:
- hostvars[item]['vm_name'].endswith(item)
loop: "{{ groups['all'] }}"

Loading…
Cancel
Save