dont clobber facts in loop (#71032)

* dont clobber facts in loop

	fixes #71031
pull/71311/head
Brian Coca 4 years ago committed by GitHub
parent 72d3d44163
commit f9af27c631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -628,7 +628,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))
@ -692,7 +692,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'

@ -13,3 +13,6 @@ ansible-playbook test_prevent_injection.yml -i inventory -v "$@"
# ensure fact merging is working properly
ansible-playbook verify_merge_facts.yml -v "$@" -e 'ansible_facts_parallel: False'
# ensure we dont clobber facts in loop
ansible-playbook prevent_clobbering.yml -v "$@"

Loading…
Cancel
Save