Ansible in a Minute · Ansible Core ·
Use until to retry a task until a condition is met
Short answer
Use until with retries and delay to poll a task until a condition is true.
Request
retry a command until stdout contains ready
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
YAML
---
- name: Retry a command until stdout contains ready
hosts: all
gather_facts: true
tasks:
- name: Retry command until stdout contains ready
ansible.builtin.shell:
cmd: your_command_here
register: command_output
until: "'ready' in command_output.stdout"
retries: 10
delay: 5
failed_when: "'ready' not in command_output.stdout"How it works
until re-runs the task until the expression is true or retries are exhausted. delay is the wait in seconds between attempts. Pair until with register so the condition can read the result.
When to use it
- Waiting for a service or file to become ready
- Polling CLI tools that succeed only after a short delay
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-09-05
Notes
Set retries and delay explicitly. Without until, Ansible does not retry the task on a false condition. Use failed_when so the task fails after retries if stdout still lacks ready.
Reference
- Retrying a task until a condition is met (Ansible docs)
Try it with BacklogZero
Ask BacklogZero to generate this automation for your environment.