-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_loop.yml
More file actions
58 lines (55 loc) · 1.48 KB
/
01_loop.yml
File metadata and controls
58 lines (55 loc) · 1.48 KB
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
---
- name: Loop Playbook
hosts: copenhagen
gather_facts: true
vars:
users:
- alice
- bob
- charlie
tasks:
- name: Print usernames
ansible.builtin.debug:
msg: "User: {{ item }}"
loop: "{{ users }}"
- name: Create multiple files
ansible.builtin.file:
path: "/tmp/{{ item }}"
state: touch
mode: '0644'
loop:
- file1.txt
- file2.txt
- file3.txt
- name: Loop over dictionary
ansible.builtin.debug:
msg: "Package {{ item.key }} should be {{ item.value }}"
loop:
- { key: 'httpd', value: 'present' }
- { key: 'vim', value: 'present' }
- { key: 'telnet', value: 'absent' }
- name: Loop with index
ansible.builtin.debug:
msg: "Item {{ idx }}: {{ item }}"
loop:
- red
- green
- blue
loop_control:
index_var: idx
- name: Create numbered files
ansible.builtin.file:
path: "/tmp/logfile{{ item }}.log"
state: touch
mode: '0644'
loop: "{{ range(1, 6) | list }}"
- name: Wait until current second is past 45
ansible.builtin.command: date +%S
register: current_seconds
until: current_seconds.stdout | int > 45
retries: 20
delay: 3
changed_when: false
- name: Show result
ansible.builtin.debug:
msg: "Succeeded after {{ current_seconds.attempts }} attempts - current second is {{ current_seconds.stdout }}"