mirror of https://github.com/ansible/ansible.git
Don't use the task for a cache, return a special cache var (#47243)
* Don't use task to cache loop results, use hostvars. Fixes #47207 * Avoid a race condition, supply _ansible_loop_cache through get_vars directly * Add tests * Add changelog fragment * Remove unnecessary copy * Remove unnecessary host from _get_delegated_vars signaturepull/47319/head
parent
9e2c02455a
commit
77d32b8f57
@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- delegate_to - When templating ``delegate_to`` in a loop, don't use the task for a cache, return a special cache through ``get_vars`` allowing looping over a hostvar (https://github.com/ansible/ansible/issues/47207)
|
@ -0,0 +1,45 @@
|
||||
- hosts: testhost,testhost2
|
||||
gather_facts: false
|
||||
vars:
|
||||
delegate_to_host: "localhost"
|
||||
tasks:
|
||||
- set_fact:
|
||||
gandalf:
|
||||
shout: 'You shall not pass!'
|
||||
when: inventory_hostname == 'testhost'
|
||||
|
||||
- set_fact:
|
||||
gandalf:
|
||||
speak: 'Run you fools!'
|
||||
when: inventory_hostname == 'testhost2'
|
||||
|
||||
- name: works correctly
|
||||
debug: var=item
|
||||
delegate_to: localhost
|
||||
with_dict: "{{ gandalf }}"
|
||||
register: result1
|
||||
|
||||
- name: shows same item for all hosts
|
||||
debug: var=item
|
||||
delegate_to: "{{ delegate_to_host }}"
|
||||
with_dict: "{{ gandalf }}"
|
||||
register: result2
|
||||
|
||||
- debug:
|
||||
var: result2.results[0].item.value
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result1.results[0].item.value == 'You shall not pass!'
|
||||
- result2.results[0].item.value == 'You shall not pass!'
|
||||
when: inventory_hostname == 'testhost'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result1.results[0].item.value == 'Run you fools!'
|
||||
- result2.results[0].item.value == 'Run you fools!'
|
||||
when: inventory_hostname == 'testhost2'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- _ansible_loop_cache is undefined
|
Loading…
Reference in New Issue