Files

80 lines
2.5 KiB
YAML
Raw Permalink Normal View History

---
- name: Roll back native MySQL delivery instance
hosts: "{{ target_hosts }}"
become: true
gather_facts: false
any_errors_fatal: true
vars:
mysql_instance: "{{ instance_name }}"
mysql_data_disk: "{{ data_disk }}"
mysql_base_dir: "{{ mysql_data_disk }}/mysql-delivery/{{ mysql_instance }}"
mysql_install_dir: "/opt/mysql-delivery/{{ mysql_instance }}"
mysql_config_file: "/etc/mysql/mysql-delivery/{{ mysql_instance }}.cnf"
mysql_run_dir: "/run/mysql-delivery-{{ mysql_instance }}"
pre_tasks:
- name: Validate rollback target
ansible.builtin.assert:
that:
- mysql_instance is match('^[a-z0-9][a-z0-9-]{0,62}$')
- mysql_data_disk is match('^/')
- mysql_data_disk != '/'
- "'..' not in mysql_data_disk"
fail_msg: "Rollback target is outside the native MySQL delivery layout"
quiet: true
tasks:
- name: Stop the delivery instance when present
ansible.builtin.systemd_service:
name: "mysql-delivery@{{ mysql_instance }}.service"
state: stopped
enabled: false
register: mysql_stop_result
failed_when: false
- name: Remove the instance systemd failure state
ansible.builtin.command:
argv:
- systemctl
- reset-failed
- "mysql-delivery@{{ mysql_instance }}.service"
changed_when: false
failed_when: false
- name: Remove the instance configuration
ansible.builtin.file:
path: "{{ mysql_config_file }}"
state: absent
- name: Remove instance-local binary links
ansible.builtin.file:
path: "{{ mysql_install_dir }}"
state: absent
- name: Remove the instance data and log tree
ansible.builtin.file:
path: "{{ mysql_base_dir }}"
state: absent
- name: Remove the instance runtime directory
ansible.builtin.file:
path: "{{ mysql_run_dir }}"
state: absent
- name: Confirm the instance artifacts are gone
ansible.builtin.stat:
path: "{{ item }}"
loop:
- "{{ mysql_config_file }}"
- "{{ mysql_install_dir }}"
- "{{ mysql_base_dir }}"
- "{{ mysql_run_dir }}"
register: mysql_rollback_artifacts
- name: Assert that all instance artifacts are gone
ansible.builtin.assert:
that:
- mysql_rollback_artifacts.results | selectattr('stat.exists') | list | length == 0
fail_msg: "One or more MySQL delivery artifacts remain after rollback"
quiet: true