mirror of https://github.com/ansible/ansible.git
Cache items when task.loop/with_items is evaluated to set delegate_to vars (#41969)
* If we evaluate task.loop/with_items when calculating delegate_to vars, cache the items. Fixes #28231 * Add comments about caching loop items * Add test for delegate_to+loop+random * Be more careful about where we update task.looppull/41127/merge
parent
11ce954226
commit
1401fa74cc
@ -0,0 +1,58 @@
|
||||
---
|
||||
- name: Integration tests for #28231
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Add some test hosts
|
||||
add_host:
|
||||
name: "foo{{item}}"
|
||||
groups: foo
|
||||
loop: "{{ range(10)|list }}"
|
||||
|
||||
# We expect all of the next 3 runs to succeeed
|
||||
# this is done multiple times to increase randomness
|
||||
- assert:
|
||||
that:
|
||||
- item in ansible_delegated_vars
|
||||
delegate_to: "{{ item }}"
|
||||
loop:
|
||||
- "{{ groups.foo|random }}"
|
||||
ignore_errors: true
|
||||
register: result1
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- item in ansible_delegated_vars
|
||||
delegate_to: "{{ item }}"
|
||||
loop:
|
||||
- "{{ groups.foo|random }}"
|
||||
ignore_errors: true
|
||||
register: result2
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- item in ansible_delegated_vars
|
||||
delegate_to: "{{ item }}"
|
||||
loop:
|
||||
- "{{ groups.foo|random }}"
|
||||
ignore_errors: true
|
||||
register: result3
|
||||
|
||||
- debug:
|
||||
var: result1
|
||||
|
||||
- debug:
|
||||
var: result2
|
||||
|
||||
- debug:
|
||||
var: result3
|
||||
|
||||
- name: Ensure all of the 3 asserts were successful
|
||||
assert:
|
||||
that:
|
||||
- results is all
|
||||
vars:
|
||||
results:
|
||||
- "{{ (result1.results|first) is successful }}"
|
||||
- "{{ (result2.results|first) is successful }}"
|
||||
- "{{ (result3.results|first) is successful }}"
|
Loading…
Reference in New Issue