Interview Prep/Ansible/Playbooks, Plays, Tasks and Handlers

How do `until`, `retries` and `delay` work?

IntermediateConceptPlaybooks, Plays, Tasks and Handlers
Answer

until re-runs a task until the condition is true, up to retries times, waiting delay seconds between attempts. The default is 3 retries and 5 seconds.

- ansible.builtin.uri:
    url: "https://{{ inventory_hostname }}/ready"
    validate_certs: false
  register: r
  until: r.status == 200
  retries: 30
  delay: 10

If the condition is never met, the task fails. Note that the task itself must not fail on a non-200, so use a module that returns the status (like uri with status_code: [200, 503]) rather than one that errors out.

All Ansible questions Roadmap: Ansible

More on Playbooks, Plays, Tasks and Handlers