How to Do Rolling Updates with Zero Downtime in Ansible
By Luca Berton · Published 2024-01-01 · Category: web-servers
How to perform rolling updates in Ansible with serial, load balancer integration, health checks, and rollback. Zero-downtime deployment patterns with examples.
How to Do Rolling Updates with Zero Downtime in Ansible
Rolling updates deploy to a subset of servers at a time, keeping your service available throughout. Ansible's serial directive makes this straightforward.
Basic Rolling Update
Serial Options
With Load Balancer Integration
Fail Fast: max_fail_percentage
Canary Deployment Pattern
FAQ
How does serial work in Ansible?
serial limits how many hosts are processed at a time. With serial: 2 and 10 hosts, Ansible deploys to 2 hosts, waits for completion, then moves to the next 2. This prevents all hosts from being down simultaneously.
What is max_fail_percentage?
max_fail_percentage stops the play if too many hosts fail. Set to 20 to abort if more than 20% of hosts in a batch fail, preventing a bad deployment from rolling out to all servers.
How do I do a canary deployment with Ansible?
Use a ramping serial: [1, 5, "25%"] or split into two plays — first targeting one host (the canary), then the rest after validation. Add a pause for manual approval between stages.
Related Articles • Ansible run_once: Execute Tasks Once • Ansible Playbook Guide • Ansible Handlers: Run Tasks on Change
Category: web-servers