How do you roll back a bad Ansible deployment?
AdvancedProductionRolling Updates, Delegation and Safe Deployments
Answer
Design for it up front:
- Deploy into versioned release directories with a
currentsymlink, so rollback is repointing the link and restarting. - Keep the previous N releases and the previous config versions (
backup: true). - Parameterise the version (
app_version), so rollback is the same playbook with the old version, or a dedicatedrollback.yml. - Use
block/rescueto revert automatically if the health check fails.
Things Ansible cannot undo: destructive database migrations, deleted data, external side effects. Make migrations backward compatible (expand and contract), so the old code still works on the new schema.
More on Rolling Updates, Delegation and Safe Deployments
How do you do a rolling update with Ansible?BeginnerWhat forms can `serial` take?IntermediateShow the standard pattern for a zero-downtime rolling deploy behind a load balancer.IntermediateWhy do you add a health check inside the deployment play?BeginnerHow do `any_errors_fatal` and `max_fail_percentage` help a rollout?BeginnerHow do you do a canary deployment?Intermediate