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

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.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Safe Deployments