mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.0 KiB
YAML
119 lines
3.0 KiB
YAML
- shell: '{{ ansible_python.executable }} -c "import tempfile; print(tempfile.mkstemp()[1])"'
|
|
register: tempfilepath
|
|
|
|
- set_fact:
|
|
until_tempfile_path: "{{ tempfilepath.stdout }}"
|
|
|
|
- name: loop with default retries
|
|
shell: echo "run" >> {{ until_tempfile_path }} && wc -w < {{ until_tempfile_path }} | tr -d ' '
|
|
register: runcount
|
|
until: runcount.stdout | int == 3
|
|
delay: 0.01
|
|
|
|
- assert:
|
|
that: runcount.stdout | int == 3
|
|
|
|
- file: path="{{ until_tempfile_path }}" state=absent
|
|
|
|
- name: loop with specified max retries
|
|
shell: echo "run" >> {{ until_tempfile_path }}
|
|
until: 1==0
|
|
retries: 5
|
|
delay: 0.01
|
|
ignore_errors: true
|
|
|
|
- name: validate output
|
|
shell: wc -l < {{ until_tempfile_path }}
|
|
register: runcount
|
|
|
|
- assert:
|
|
that: runcount.stdout | int == 6 # initial + 5 retries
|
|
|
|
- file:
|
|
path: "{{ until_tempfile_path }}"
|
|
state: absent
|
|
|
|
- name: Test failed_when impacting until
|
|
shell: 'true'
|
|
register: failed_when_until
|
|
failed_when: True
|
|
until: failed_when_until is successful
|
|
retries: 3
|
|
delay: 0.5
|
|
ignore_errors: True
|
|
|
|
- assert:
|
|
that:
|
|
- failed_when_until.attempts == 3
|
|
|
|
- name: Test changed_when impacting until
|
|
shell: 'true'
|
|
register: changed_when_until
|
|
changed_when: False
|
|
until: changed_when_until is changed
|
|
retries: 3
|
|
delay: 0.5
|
|
ignore_errors: True
|
|
|
|
- assert:
|
|
that:
|
|
- changed_when_until.attempts == 3
|
|
|
|
# This task shouldn't fail, previously .attempts was not available to changed_when/failed_when
|
|
# and would cause the conditional to fail due to ``'dict object' has no attribute 'attempts'``
|
|
# https://github.com/ansible/ansible/issues/34139
|
|
- name: Test access to attempts in changed_when/failed_when
|
|
shell: 'true'
|
|
register: changed_when_attempts
|
|
until: 1 == 0
|
|
retries: 5
|
|
delay: 0.5
|
|
failed_when: changed_when_attempts.attempts > 6
|
|
|
|
# Test until on module that doesn't return failed, but does return rc
|
|
- name: create counter file
|
|
copy:
|
|
dest: "{{ output_dir }}/until_counter"
|
|
content: 3
|
|
|
|
- shell_no_failed:
|
|
cmd: |
|
|
COUNTER=$(cat "{{ output_dir }}/until_counter"); NEW=$(expr $COUNTER - 1); echo $NEW > "{{ output_dir }}/until_counter"; exit $COUNTER
|
|
register: counter
|
|
delay: 0.5
|
|
until: counter.rc == 0
|
|
|
|
- name: test retries without explicit until, defaults to "until task succeeds"
|
|
block:
|
|
- name: EXPECTED FAILURE
|
|
fail:
|
|
retries: 3
|
|
delay: 0.1
|
|
register: r
|
|
ignore_errors: true
|
|
|
|
- assert:
|
|
that:
|
|
- r.attempts == 3
|
|
|
|
- vars:
|
|
test_file: "{{ lookup('env', 'OUTPUT_DIR') }}/until_success_test_file"
|
|
block:
|
|
- file:
|
|
name: "{{ test_file }}"
|
|
state: absent
|
|
|
|
- name: fail on the first invocation, succeed on the second
|
|
shell: "[ -f {{ test_file }} ] || (touch {{ test_file }} && false)"
|
|
retries: 5
|
|
delay: 0.1
|
|
register: r
|
|
always:
|
|
- file:
|
|
name: "{{ test_file }}"
|
|
state: absent
|
|
|
|
- assert:
|
|
that:
|
|
- r.attempts == 2
|