summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/var_templating/task_vars_templating.yml
blob: 88e1e6048afbc02da9d5a6e0c43c354921129eb9 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
- hosts: localhost
  connection: local
  gather_facts: no
  tasks:
  - add_host:
      name: host1
      ansible_connection: local
      ansible_host: 127.0.0.1

- hosts: all
  gather_facts: no
  tasks:
    - debug:
        msg: "{{ hostvars['host1']['x'] }}"
      register: x_1
    - debug:
        msg: "{{ hostvars['host1']['y'] }}"
      register: y_1
    - debug:
        msg: "{{ hostvars_['x'] }}"
      vars:
        hostvars_: "{{ hostvars['host1'] }}"
      register: x_2
    - debug:
        msg: "{{ hostvars_['y'] }}"
      vars:
        hostvars_: "{{ hostvars['host1'] }}"
      register: y_2

    - assert:
        that:
          - x_1 == x_2
          - y_1 == y_2
          - x_1 == y_1

    - debug:
        msg: "{{ hostvars['host1']['nested_x']['value'] }}"
      register: x_1
    - debug:
        msg: "{{ hostvars['host1']['nested_y']['value'] }}"
      register: y_1
    - debug:
        msg: "{{ hostvars_['nested_x']['value'] }}"
      vars:
        hostvars_: "{{ hostvars['host1'] }}"
      register: x_2
    - debug:
        msg: "{{ hostvars_['nested_y']['value'] }}"
      vars:
        hostvars_: "{{ hostvars['host1'] }}"
      register: y_2

    - assert:
        that:
          - x_1 == x_2
          - y_1 == y_2
          - x_1 == y_1