dont clobber facts in loop (#71032) (#71096)

* dont clobber facts in loop

	fixes #71031

(cherry picked from commit f9af27c631)
pull/71192/head
Brian Coca 4 years ago committed by GitHub
parent 6e8adc0526
commit 4a6a9acea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- avoid clobbering existing facts inside loop when task also returns ansible_facts.

@ -715,7 +715,7 @@ class TaskExecutor:
else:
# TODO: cleaning of facts should eventually become part of taskresults instead of vars
af = wrap_var(result['ansible_facts'])
vars_copy.update(namespace_facts(af))
vars_copy['ansible_facts'] = combine_vars(vars_copy.get('ansible_facts', {}), namespace_facts(af))
if C.INJECT_FACTS_AS_VARS:
vars_copy.update(clean_facts(af))
@ -779,7 +779,7 @@ class TaskExecutor:
else:
# TODO: cleaning of facts should eventually become part of taskresults instead of vars
af = wrap_var(result['ansible_facts'])
variables.update(namespace_facts(af))
variables['ansible_facts'] = combine_vars(variables.get('ansible_facts', {}), namespace_facts(af))
if C.INJECT_FACTS_AS_VARS:
variables.update(clean_facts(af))

@ -0,0 +1,8 @@
- name: Verify existing facts don't go undefined on unrelated new facts in loop
hosts: localhost
gather_facts: True
tasks:
- name: Ensure that 'virtualization_type' is not undefined after first loop iteration
bogus_facts:
loop: [1, 2, 3]
when: ansible_facts['virtualization_type'] != 'NotDocker'

@ -10,3 +10,6 @@ ANSIBLE_GATHERING=smart ansible-playbook test_run_once.yml -i inventory -v "$@"
# ensure clean_facts is working properly
ansible-playbook test_prevent_injection.yml -i inventory -v "$@"
# ensure we dont clobber facts in loop
ansible-playbook prevent_clobbering.yml -v "$@"

Loading…
Cancel
Save