summaryrefslogtreecommitdiffstats
path: root/examples/playbooks/rule-deprecated-bare-vars-pass.yml
blob: c7e65217f89038fcf1ece8d37b610493451af652 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
- name: Using bare variables success
  hosts: localhost
  become: false
  vars:
    my_list:
      - foo
      - bar

    my_list2:
      - 1
      - 2

    my_list_of_dicts:
      - foo: 1
        bar: 2
      - foo: 3
        bar: 4

    my_list_of_lists:
      - "{{ my_list }}"
      - "{{ my_list2 }}"

    my_filenames:
      - foo.txt
      - bar.txt

    my_dict:
      foo: bar

  tasks:
    ### Testing with_items loops
    - name: Use with_items loop using static list
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_items:
        - foo
        - bar

    - name: Use with_items using a static hash
      ansible.builtin.debug:
        msg: "{{ item.key }} - {{ item.value }}"
      with_items:
        - { key: foo, value: 1 }
        - { key: bar, value: 2 }

    - name: Use with_items loop using variable
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_items: "{{ my_list }}"

    ### Testing with_nested loops
    - name: Use with_nested loop using static lists
      ansible.builtin.debug:
        msg: "{{ item[0] }} - {{ item[1] }}"
      with_nested:
        - [foo, bar]
        - ["1", "2", "3"]

    - name: Use with_nested loop using variable list and static
      ansible.builtin.debug:
        msg: "{{ item[0] }} - {{ item[1] }}"
      with_nested:
        - "{{ my_list }}"
        - ["1", "2", "3"]

    ### Testing with_dict
    - name: Use with_dict loop using variable
      ansible.builtin.debug:
        msg: "{{ item.key }} - {{ item.value }}"
      with_dict: "{{ my_dict }}"

    ### Testing with_dict with a default empty dictionary
    - name: Use with_dict loop using variable and default
      ansible.builtin.debug:
        msg: "{{ item.key }} - {{ item.value }}"
      with_dict: "{{ uwsgi_ini | default({}) }}"

    ### Testing with_file
    - name: Use with_file loop using static files list
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_file:
        - foo.txt
        - bar.txt

    - name: Use with_file loop using list of filenames
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_file: "{{ my_filenames }}"

    ### Testing with_fileglob
    - name: Use with_fileglob loop using list of *.txt
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_fileglob:
        - "*.txt"

    ### Testing non-list form of with_fileglob
    - name: Use with_fileglob loop using single value *.txt
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_fileglob: "*.txt"

    ### Testing non-list form of with_fileglob with trailing templated pattern
    - name: Use with_fileglob loop using templated pattern
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_fileglob: foo{{ glob }}

    ### Testing with_together
    - name: Use with_together loop using variable lists
      ansible.builtin.debug:
        msg: "{{ item.0 }} - {{ item.1 }}"
      with_together:
        - "{{ my_list }}"
        - "{{ my_list2 }}"

    - name: Use with_subelements loop
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_subelements:
        - "{{ my_list_of_dicts }}"
        - bar

    - name: Use with_sequence loop
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_sequence: count=2

    - name: Use with_random_choice loop
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_random_choice: "{{ my_list }}"

    - name: Use with_first_found loop with static files list
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_first_found:
        - foo.txt
        - bar.txt

    - name: Use with_first_found loop with list of filenames
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_first_found: "{{ my_filenames }}"

    - name: Use with_indexed_items loop
      ansible.builtin.debug:
        msg: "{{ item.0 }} {{ item.1 }}"
      with_indexed_items: "{{ my_list }}"

    - name: Use with_ini loop
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_ini: value[1-2] section=section1 file=foo.ini re=true

    - name: Use with_inventory_hostnames loop
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_inventory_hostnames: all

    - name: Test more complex jinja is also allowed
      ansible.builtin.debug:
        msg: "{{ item }}"
      with_items: >-
        {%- set ns = [1, 1, 2] -%}
        {{- ns.keys | unique -}}