Debian Codegraph @

test/integration/targets/until/tasks/main.yml

raw
1 - shell: '{{ ansible_python.executable }} -c "import tempfile; print(tempfile.mkstemp()[1])"'
2 register: tempfilepath
3
4 - set_fact:
5 until_tempfile_path: "{{ tempfilepath.stdout }}"
6
7 - name: loop with default retries
8 shell: echo "run" >> {{ until_tempfile_path }} && wc -w < {{ until_tempfile_path }} | tr -d ' '
9 register: runcount
10 until: runcount.stdout | int == 3
11 delay: 0.01
12
13 - assert:
14 that: runcount.stdout | int == 3
15
16 - file: path="{{ until_tempfile_path }}" state=absent
17
18 - name: loop with specified max retries
19 shell: echo "run" >> {{ until_tempfile_path }}
20 until: 1==0
21 retries: 5
22 delay: 0.01
23 ignore_errors: true
24
25 - name: validate output
26 shell: wc -l < {{ until_tempfile_path }}
27 register: runcount
28
29 - assert:
30 that: runcount.stdout | int == 6 # initial + 5 retries
31
32 - file:
33 path: "{{ until_tempfile_path }}"
34 state: absent
35
36 - name: Test failed_when impacting until
37 shell: 'true'
38 register: failed_when_until
39 failed_when: True
40 until: failed_when_until is successful
41 retries: 3
42 delay: 0.5
43 ignore_errors: True
44
45 - assert:
46 that:
47 - failed_when_until.attempts == 3
48
49 - name: Test changed_when impacting until
50 shell: 'true'
51 register: changed_when_until
52 changed_when: False
53 until: changed_when_until is changed
54 retries: 3
55 delay: 0.5
56 ignore_errors: True
57
58 - assert:
59 that:
60 - changed_when_until.attempts == 3
61
62 # This task shouldn't fail, previously .attempts was not available to changed_when/failed_when
63 # and would cause the conditional to fail due to ``'dict object' has no attribute 'attempts'``
64 # https://github.com/ansible/ansible/issues/34139
65 - name: Test access to attempts in changed_when/failed_when
66 shell: 'true'
67 register: changed_when_attempts
68 until: 1 == 0
69 retries: 5
70 delay: 0.5
71 failed_when: changed_when_attempts.attempts > 6
72
73 # Test until on module that doesn't return failed, but does return rc
74 - name: create counter file
75 copy:
76 dest: "{{ output_dir }}/until_counter"
77 content: 3
78
79 - shell_no_failed:
80 cmd: |
81 COUNTER=$(cat "{{ output_dir }}/until_counter"); NEW=$(expr $COUNTER - 1); echo $NEW > "{{ output_dir }}/until_counter"; exit $COUNTER
82 register: counter
83 delay: 0.5
84 until: counter.rc == 0
85
86 - name: test retries without explicit until, defaults to "until task succeeds"
87 block:
88 - name: EXPECTED FAILURE
89 fail:
90 retries: 3
91 delay: 0.1
92 register: r
93 ignore_errors: true
94
95 - assert:
96 that:
97 - r.attempts == 3
98
99 - vars:
100 test_file: "{{ lookup('env', 'OUTPUT_DIR') }}/until_success_test_file"
101 block:
102 - file:
103 name: "{{ test_file }}"
104 state: absent
105
106 - name: fail on the first invocation, succeed on the second
107 shell: "[ -f {{ test_file }} ] || (touch {{ test_file }} && false)"
108 retries: 5
109 delay: 0.1
110 register: r
111 always:
112 - file:
113 name: "{{ test_file }}"
114 state: absent
115
116 - assert:
117 that:
118 - r.attempts == 2