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

How do you deploy application releases idempotently with a rollback path?

IntermediateProductionRolling Updates, Delegation and Safe Deployments
Answer

Use release directories and an atomic symlink swap, so each deploy is a new directory and the switch is instantaneous.

- ansible.builtin.unarchive:
    src: "{{ artifact_url }}"
    dest: "/srv/app/releases/{{ app_version }}"
    remote_src: true
    creates: "/srv/app/releases/{{ app_version }}/.deployed"

- ansible.builtin.file:
    src: "/srv/app/releases/{{ app_version }}"
    dest: /srv/app/current
    state: link
  notify: Restart app

Clean old releases with find and keep the last five. Rollback is the same symlink task with the previous version, followed by a restart.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Safe Deployments