Ansible: Retry processing

This post shows how to retry Ansible module in Playbook.
To retry, use until.

Retry by until

The following is a sample of playbook that retry script module by the result of script.

---
- name: Test Playbook
  hosts: 192.168.1.1

  tasks:
  - name: Run Script
    until: ret.rc == 0
    script: ./test-script.ps1
    register: ret
    retries: 5
    delay: 5

If test-script.ps1 returns none-zero, retry 5 times in interval of 5 seconds.

ret.rc is returned value of script module. Run until that is zero.

    until: ret.rc == 0

Store the returned value of test-script.ps1 in ret by register.

    script: ./test-script.ps1
    register: ret

retries means the number of times of retry.

    retries: 5

delay means the interval of retry. The unit is second. Default value is 1 second.

    delay: 5

That is about it.