Skip to content

Commit

Permalink
dont clobber facts in loop (ansible#71032)
Browse files Browse the repository at this point in the history
* dont clobber facts in loop

	fixes ansible#71031
  • Loading branch information
bcoca authored Aug 4, 2020
1 parent 72d3d44 commit f9af27c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ansible/executor/task_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def _evaluate_failed_when_result(result):
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))

Expand Down Expand Up @@ -692,7 +692,7 @@ def _evaluate_failed_when_result(result):
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))

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 3 additions & 0 deletions test/integration/targets/gathering_facts/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"

0 comments on commit f9af27c

Please sign in to comment.