Learning Ansible
You can retry a task a number of times, or until a condition is met.
One example is to retry tasks that depend on something external, like installing a package that depends on a repository.
---
- name: Retry something
hosts: all
tasks:
- name: Install some package.
ansible.builtin.package:
name: some_package
register: result
until: result is not failed
retries: 2
delay: 10
The
retries
is the number of attempts after the first one. So aretries: 2
means the job is attempted 3 times.
Write a playbook that:
stat
to check if a file exists.This solution works.