Retry task 10 times with interval 1 second until return code of the command will not be 0. Ignore if even all tries will fail.
---
- hosts: all
connection: local
tasks:
- shell: exit 1
register: task_result
until: task_result.rc == 0
retries: 10
delay: 1
ignore_errors: yes
Also you can check another properties like task_result.stderr
, task_result.stdout
, task_result.changed
and combine the into logical expressions.
To quickly check task on a localhost use following command:
ansible-playbook retry.yml -i localhost,
(trailing comma should be present)
This was exactly what I needed. However there is a logic error in the first sentence. It should read "... until the return code of the command IS 0."