What is the rollback strategy for Ansible?

Rollback strategies in Ansible are crucial for ensuring system stability and recovery during deployments. When an update fails or causes issues, having a rollback plan allows you to revert changes effectively. This is typically achieved through the use of Ansible’s features like playbook reversibility, state management, and version control practices.

One common rollback strategy is to maintain a backup of configurations and applications before making changes. If the deployment encounters problems, the previous version can be restored using Ansible playbooks.

Example of a simple rollback strategy using Ansible:

- name: Backup current configuration copy: src: /etc/myapp/config.toml dest: /etc/myapp/config.toml.bak remote_src: yes - name: Deploy new configuration template: src: config.toml.j2 dest: /etc/myapp/config.toml - name: Check if myapp is running command: systemctl status myapp register: myapp_status ignore_errors: yes - name: Rollback if myapp is not running copy: src: /etc/myapp/config.toml.bak dest: /etc/myapp/config.toml when: myapp_status.rc != 0 - name: Restart myapp service: name: myapp state: restarted

Ansible rollback strategy Ansible deployment Ansible recovery Ansible configuration management