dont clobber facts in loop (#71032)

* dont clobber facts in loop

	fixes #71031
This commit is contained in:
Brian Coca 2020-08-04 15:41:42 -04:00 committed by GitHub
parent 72d3d44163
commit f9af27c631
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View file

@ -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))

View file

@ -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'

View file

@ -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 "$@"