-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnested-loop.yml
33 lines (29 loc) · 951 Bytes
/
nested-loop.yml
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
# I had a need to do nested loops and found this https://docs.ansible.com/ansible/2.3/playbooks_loops.html#nested-loops that inspired me to create this playbook
- name: Nested loop
hosts: localhost
tasks:
- name: Echos
shell: \
echo "file:{{ item[0]['file'] }} regexp:{{ item[1]['regexp'] }} line:{{ item[1]['line'] }}"
# - debug:
# var: item
with_nested:
- "{{ files }}"
- "{{ updates }}"
register: echos
- debug:
# var: echos['results']['stdout_lines']
msg:
- "{{ echos['results'][0]['stdout_lines'][0] }}"
- "{{ echos['results'][1]['stdout_lines'][0] }}"
- "{{ echos['results'][2]['stdout_lines'][0] }}"
- "{{ echos['results'][3]['stdout_lines'][0] }}"
vars:
files:
- file: /tmp/file1
- file: /tmp/file2
updates:
- regexp: regexp1
line: line1
- regexp: regexp2
line: line2