How to Retry a Failed Task in Ansible (retries, delay, until)
By Luca Berton · Published 2024-01-01 · Category: installation
How to retry failed tasks in Ansible using retries, delay, and until. Handle transient failures, wait for services, and implement resilient playbooks with examples.
How to Retry a Failed Task in Ansible (retries, delay, until)
Transient failures happen — APIs timeout, services take time to start, packages fail to download. Ansible's retry mechanism handles this gracefully.
Basic Retry
Retry Package Installation
Retry with Complex Conditions
Retry API Calls
Retry with Backoff Pattern
Default Values
Without explicit parameters: • retries defaults to 3 • delay defaults to 5 seconds • until is required for retries to activate
FAQ
How do I retry a failed task in Ansible?
Use until, retries, and delay on any task: until: result is success with retries: 5 and delay: 10. The task retries up to 5 times, waiting 10 seconds between attempts.
What is the difference between retries and block/rescue?
retries re-attempts the same task multiple times (good for transient failures). block/rescue catches failures and runs alternative recovery tasks (good for fallback logic).
Does Ansible support exponential backoff?
Not natively. The delay is fixed between retries. For exponential backoff, use a loop with increasing delay values or implement it in a custom module.
Related Articles • Ansible Error Handling: block/rescue/always • Ansible uri Module: HTTP Requests • Ansible Playbook Guide
Category: installation