matrix-docker-ansible-deploy/roles/matrix-ma1sd/tasks/migrate_mxisd.yml

72 lines
2.7 KiB
YAML
Raw Normal View History

2020-04-02 15:19:40 +00:00
---
# This task is for migrating existing mxisd data when transitioning to the ma1sd fork.
- name: Check for existent mxisd data
2022-07-18 08:22:05 +00:00
ansible.builtin.stat:
path: "{{ matrix_base_data_path }}/mxisd/data"
2020-04-02 15:19:40 +00:00
register: ma1sd_migrate_mxisd_data_dir_stat
- name: Warn if mxisd data detected
ansible.builtin.debug:
2020-04-02 15:19:40 +00:00
msg: >
You seem to have an existing mxisd folder in `{{ matrix_base_data_path }}/mxisd`.
2020-04-02 15:19:40 +00:00
We are going to migrate it to ma1sd and rename the folder to mxisd.migrated.
when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists"
- name: Check existence of old matrix-mxisd service
2022-07-18 08:22:05 +00:00
ansible.builtin.stat:
2020-04-02 15:19:40 +00:00
path: "{{ matrix_systemd_path }}/matrix-mxisd.service"
register: matrix_mxisd_service_stat
- name: Ensure matrix-mxisd is stopped
ansible.builtin.service:
2020-04-02 15:19:40 +00:00
name: matrix-mxisd
state: stopped
enabled: false
daemon_reload: true
when: "matrix_mxisd_service_stat.stat.exists"
2020-04-02 15:19:40 +00:00
- name: Check existence of matrix-ma1sd service
2022-07-18 08:22:05 +00:00
ansible.builtin.stat:
2020-04-02 15:19:40 +00:00
path: "{{ matrix_systemd_path }}/matrix-ma1sd.service"
register: matrix_ma1sd_service_stat
when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists"
- name: Ensure matrix-ma1sd is stopped
ansible.builtin.service:
2020-04-02 15:19:40 +00:00
name: matrix-ma1sd
state: stopped
daemon_reload: true
2020-04-02 15:19:40 +00:00
when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists and matrix_ma1sd_service_stat.stat.exists"
# We use shell commands for the migration, because the Ansible copy module cannot
# recursively copy remote directories (like `/matrix/mxisd/data/sign.key`) in older versions of Ansible.
- block:
- name: Copy mxisd data files to ma1sd folder
ansible.builtin.command: "cp -ar {{ matrix_base_data_path }}/mxisd/data {{ matrix_ma1sd_base_path }}"
2020-04-02 15:19:40 +00:00
- name: Check existence of mxisd.db file
2022-07-18 08:22:05 +00:00
ansible.builtin.stat:
path: "{{ matrix_ma1sd_data_path }}/mxisd.db"
register: matrix_ma1sd_mxisd_db_stat
2020-04-02 15:19:40 +00:00
- name: Rename database (mxisd.db -> ma1sd.db)
ansible.builtin.command: "mv {{ matrix_ma1sd_data_path }}/mxisd.db {{ matrix_ma1sd_data_path }}/ma1sd.db"
when: "matrix_ma1sd_mxisd_db_stat.stat.exists"
- name: Rename mxisd folder
ansible.builtin.command: "mv {{ matrix_base_data_path }}/mxisd {{ matrix_base_data_path }}/mxisd.migrated"
2020-04-02 15:19:40 +00:00
when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists"
- name: Ensure outdated matrix-mxisd.service doesn't exist
ansible.builtin.file:
2020-04-02 15:19:40 +00:00
path: "{{ matrix_systemd_path }}/matrix-mxisd.service"
state: absent
when: "matrix_mxisd_service_stat.stat.exists"
2020-04-02 15:19:40 +00:00
- name: Ensure systemd reloaded after removing outdated matrix-mxisd.service
ansible.builtin.service:
daemon_reload: true
when: "matrix_mxisd_service_stat.stat.exists"