summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/delegate_to/delegate_facts_loop.yml
blob: b05c4064025d0fe6565a522cc2832fe977ec7b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
- hosts: localhost
  gather_facts: no
  tasks:
    - set_fact:
        test: 123
      delegate_to: "{{ item }}"
      delegate_facts: true
      loop: "{{ groups['all'] | difference(['localhost']) }}"

    - name: ensure we didnt create it on current host
      assert:
        that:
          - test is undefined

    - name: ensure facts get created
      assert:
        that:
          - "'test' in hostvars[item]"
          - hostvars[item]['test'] == 123
      loop: "{{ groups['all'] | difference(['localhost'])}}"


- name: test that we don't polute whole group with one value
  hosts: localhost
  gather_facts: no
  vars:
    cluster_name: bleh
  tasks:
  - name: construct different fact per host in loop
    set_fact:
      vm_name: "{{ cluster_name }}-{{item}}"
    delegate_to: "{{ item }}"
    delegate_facts: True
    with_items: "{{ groups['all'] }}"

  - name: ensure the fact is personalized for each host
    assert:
      that:
        - hostvars[item]['vm_name'].endswith(item)
    loop: "{{ groups['all'] }}"