blob: c8f0f3fbcebd4de65f6fc37c699cb6a21ac144ce (
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
---
- hosts: localhost
become: no
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: with_items loop using static list
debug:
msg: "{{ item }}"
with_items:
- foo
- bar
- name: with_items using a static hash
debug:
msg: "{{ item.key }} - {{ item.value }}"
with_items:
- { key: foo, value: 1 }
- { key: bar, value: 2 }
- name: with_items loop using variable
debug:
msg: "{{ item }}"
with_items: "{{ my_list }}"
### Testing with_nested loops
- name: with_nested loop using static lists
debug:
msg: "{{ item[0] }} - {{ item[1] }}"
with_nested:
- [ 'foo', 'bar' ]
- [ '1', '2', '3' ]
- name: with_nested loop using variable list and static
debug:
msg: "{{ item[0] }} - {{ item[1] }}"
with_nested:
- "{{ my_list }}"
- [ '1', '2', '3' ]
### Testing with_dict
- name: with_dict loop using variable
debug:
msg: "{{ item.key }} - {{ item.value }}"
with_dict: "{{ my_dict }}"
### Testing with_dict with a default empty dictionary
- name: with_dict loop using variable and default
debug:
msg: "{{ item.key }} - {{ item.value }}"
with_dict: "{{ uwsgi_ini | default({}) }}"
### Testing with_file
- name: with_file loop using static files list
debug:
msg: "{{ item }}"
with_file:
- foo.txt
- bar.txt
- name: with_file loop using list of filenames
debug:
msg: "{{ item }}"
with_file: "{{ my_filenames }}"
### Testing with_fileglob
- name: with_fileglob loop using list of *.txt
debug:
msg: "{{ item }}"
with_fileglob:
- '*.txt'
### Testing non-list form of with_fileglob
- name: with_fileglob loop using single value *.txt
debug:
msg: "{{ item }}"
with_fileglob: '*.txt'
### Testing non-list form of with_fileglob with trailing templated pattern
- name: with_fileglob loop using templated pattern
debug:
msg: "{{ item }}"
with_fileglob: 'foo{{glob}}'
### Testing with_filetree
- name: with_filetree loop using list of path
debug:
msg: "{{ item }}"
with_filetree:
- path/to/dir1/
- path/to/dir2/
### Testing non-list form of with_filetree
- name: with_filetree loop using single path
debug:
msg: "{{ item }}"
with_filetree: path/to/dir/
### Testing non-list form of with_filetree with trailing templated pattern
- name: with_filetree loop using templated pattern
debug:
msg: "{{ item }}"
with_filetree: 'path/to/{{ directory }}'
### Testing with_together
- name: with_together loop using variable lists
debug:
msg: "{{ item.0 }} - {{ item.1 }}"
with_together:
- "{{ my_list }}"
- "{{ my_list2 }}"
- name: with_subelements loop
debug:
msg: "{{ item }}"
with_subelements:
- "{{ my_list_of_dicts }}"
- bar
- name: with_sequence loop
debug:
msg: "{{ item }}"
with_sequence: count=2
- name: with_random_choice loop
debug:
msg: "{{ item }}"
with_random_choice: "{{ my_list }}"
- name: with_first_found loop with static files list
debug:
msg: "{{ item }}"
with_first_found:
- foo.txt
- bar.txt
- name: with_first_found loop with list of filenames
debug:
msg: "{{ item }}"
with_first_found: "{{ my_filenames }}"
- name: with_indexed_items loop
debug:
msg: "{{ item.0 }} {{ item.1 }}"
with_indexed_items: "{{ my_list }}"
- name: with_ini loop
debug:
msg: "{{ item }}"
with_ini: value[1-2] section=section1 file=foo.ini re=true
- name: with_flattened loop
debug:
msg: "{{ item }}"
with_flattened:
- "{{ my_list }}"
- "{{ my_list2 }}"
- name: with_flattened loop with a variable
debug:
msg: "{{ item }}"
with_flattened: "{{ my_list_of_lists }}"
- name: with_flattened loop with a multiline template
debug:
msg: "{{ item }}"
with_flattened: >
{{ my_list
| union(my_list2)
| list }}
- name: with_inventory_hostnames loop
debug:
msg: "{{ item }}"
with_inventory_hostnames: all
|