Show the standard pattern for a zero-downtime rolling deploy behind a load balancer.
IntermediateProductionRolling Updates, Delegation and Safe Deployments
Answer
Take each host out of rotation, change it, verify it, put it back, in small batches.
- hosts: web
serial: "25%"
max_fail_percentage: 0
pre_tasks:
- community.general.haproxy:
state: disabled
host: "{{ inventory_hostname }}"
backend: app
wait: true
delegate_to: "{{ groups['lb'][0] }}"
roles:
- app
post_tasks:
- ansible.builtin.uri:
url: "http://{{ inventory_hostname }}:8080/health"
status_code: 200
register: h
until: h.status == 200
retries: 20
delay: 3
- community.general.haproxy:
state: enabled
host: "{{ inventory_hostname }}"
backend: app
delegate_to: "{{ groups['lb'][0] }}"
max_fail_percentage: 0 stops the rollout on the first failed host, leaving the rest on the old, working version.
More on Rolling Updates, Delegation and Safe Deployments
How do you do a rolling update with Ansible?BeginnerWhat forms can `serial` take?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?IntermediateHow would you implement blue/green deployment with Ansible?Advanced