Debian Codegraph @

test/integration/targets/delegate_to/delegate_facts_loop.yml

raw
1 - hosts: localhost
2 gather_facts: no
3 tasks:
4 - set_fact:
5 test: 123
6 delegate_to: "{{ item }}"
7 delegate_facts: true
8 loop: "{{ groups['all'] | difference(['localhost']) }}"
9
10 - name: ensure we didn't create it on current host
11 assert:
12 that:
13 - test is undefined
14
15 - name: ensure facts get created
16 assert:
17 that:
18 - "'test' in hostvars[item]"
19 - hostvars[item]['test'] == 123
20 loop: "{{ groups['all'] | difference(['localhost'])}}"
21
22
23 - name: test that we don't pollute whole group with one value
24 hosts: localhost
25 gather_facts: no
26 vars:
27 cluster_name: bleh
28 tasks:
29 - name: construct different fact per host in loop
30 set_fact:
31 vm_name: "{{ cluster_name }}-{{item}}"
32 delegate_to: "{{ item }}"
33 delegate_facts: True
34 with_items: "{{ groups['all'] }}"
35
36 - name: ensure the fact is personalized for each host
37 assert:
38 that:
39 - hostvars[item]['vm_name'].endswith(item)
40 loop: "{{ groups['all'] }}"