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

Why do you add a health check inside the deployment play?

BeginnerProductionRolling Updates, Delegation and Safe Deployments
Answer

A service restart that returns success only means the process started. A health check proves it serves traffic. Without it, Ansible moves on to the next batch and you can break all hosts with one bad build.

- ansible.builtin.uri:
    url: http://localhost:8080/health
    status_code: 200
  register: r
  until: r.status == 200
  retries: 15
  delay: 4

Make the check meaningful (dependencies reachable, version reported matches what you deployed), not just "port is open". If it never passes the task fails and the batch stops.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Safe Deployments