Ansible retry task
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: yesAlso 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)
Written by Misha Behersky
Related protips
1 Response
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."
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Ansible 
Authors
 
Misha Behersky
79.79K
 
tartansandal
73.67K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#
 
 
