summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/delegate_to
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2018-06-26 22:10:04 +0200
committerGitHub <noreply@github.com>2018-06-26 22:10:04 +0200
commit1401fa74cc39b44ea6ddd1d4b5c5eac9fb82bbf9 (patch)
treef0cb1342afbe2a8897027bbc5c7ed1991b33b111 /test/integration/targets/delegate_to
parentFix docs for all test. Fixes #41956 (#41965) (diff)
downloadansible-1401fa74cc39b44ea6ddd1d4b5c5eac9fb82bbf9.tar.xz
ansible-1401fa74cc39b44ea6ddd1d4b5c5eac9fb82bbf9.zip
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.loop
Diffstat (limited to 'test/integration/targets/delegate_to')
-rwxr-xr-xtest/integration/targets/delegate_to/runme.sh2
-rw-r--r--test/integration/targets/delegate_to/test_delegate_to_loop_randomness.yml58
2 files changed, 60 insertions, 0 deletions
diff --git a/test/integration/targets/delegate_to/runme.sh b/test/integration/targets/delegate_to/runme.sh
index 3d2873ee44..38514c37b8 100755
--- a/test/integration/targets/delegate_to/runme.sh
+++ b/test/integration/targets/delegate_to/runme.sh
@@ -6,3 +6,5 @@ ANSIBLE_SSH_ARGS='-C -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHos
ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook test_delegate_to.yml -i ../../inventory -v "$@"
ansible-playbook test_loop_control.yml -v "$@"
+
+ansible-playbook test_delegate_to_loop_randomness.yml -v "$@"
diff --git a/test/integration/targets/delegate_to/test_delegate_to_loop_randomness.yml b/test/integration/targets/delegate_to/test_delegate_to_loop_randomness.yml
new file mode 100644
index 0000000000..b43e884a0c
--- /dev/null
+++ b/test/integration/targets/delegate_to/test_delegate_to_loop_randomness.yml
@@ -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 }}"