How do you automatically roll back with `block/rescue`?
IntermediateProductionRolling Updates, Delegation and Safe Deployments
Answer
- block:
- ansible.builtin.include_tasks: deploy.yml
- ansible.builtin.uri:
url: http://localhost:8080/health
status_code: 200
register: h
until: h.status == 200
retries: 10
delay: 3
rescue:
- ansible.builtin.include_tasks: rollback.yml
- ansible.builtin.fail:
msg: "Deploy of {{ app_version }} failed, rolled back to {{ previous_version }}"
Finish the rescue with fail, otherwise the host counts as rescued, and max_fail_percentage will not stop the rollout, so the next batch would deploy the same broken version.
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