Interview Prep/Ansible/Rolling Updates, Delegation and Safe Deployments

How do you restart services without downtime in a play?

IntermediateProductionRolling Updates, Delegation and Safe Deployments
Answer

Prefer reload to restart when the service supports it. For full restarts use serial so capacity remains, remove the host from the load balancer, flush handlers, check health and re-enable.

- ansible.builtin.template:
    src: app.conf.j2
    dest: /etc/app/app.conf
  notify: Restart app

- ansible.builtin.meta: flush_handlers

- ansible.builtin.wait_for:
    port: 8080
    timeout: 60

flush_handlers guarantees the restart happens before the readiness check instead of at the end of the play.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Safe Deployments