mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2024-12-25 18:38:30 +01:00
77 lines
2.8 KiB
YAML
77 lines
2.8 KiB
YAML
---
|
|
|
|
- name: Fail if Postgres not enabled
|
|
ansible.builtin.fail:
|
|
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate."
|
|
when: "not matrix_postgres_enabled | bool"
|
|
|
|
# Defaults
|
|
|
|
- name: Set postgres_start_wait_time, if not provided
|
|
ansible.builtin.set_fact:
|
|
postgres_start_wait_time: 15
|
|
when: "postgres_start_wait_time | default('') == ''"
|
|
|
|
# Actual import work
|
|
|
|
- name: Ensure matrix-postgres is started
|
|
ansible.builtin.service:
|
|
name: matrix-postgres
|
|
state: started
|
|
daemon_reload: true
|
|
register: matrix_postgres_service_start_result
|
|
|
|
- name: Wait a bit, so that Postgres can start
|
|
ansible.builtin.wait_for:
|
|
timeout: "{{ postgres_start_wait_time }}"
|
|
delegate_to: 127.0.0.1
|
|
become: false
|
|
when: "matrix_postgres_service_start_result.changed | bool"
|
|
|
|
- name: Check existence of matrix-appservice-irc service
|
|
ansible.builtin.stat:
|
|
path: "{{ matrix_systemd_path }}/matrix-appservice-irc.service"
|
|
register: matrix_appservice_irc_service_stat
|
|
|
|
- name: Ensure matrix-appservice-irc is stopped
|
|
ansible.builtin.service:
|
|
name: matrix-appservice-irc
|
|
state: stopped
|
|
when: "matrix_appservice_irc_service_stat.stat.exists"
|
|
|
|
- name: Import appservice-irc NeDB database into Postgres
|
|
ansible.builtin.command:
|
|
cmd: >-
|
|
{{ matrix_host_command_docker }} run
|
|
--rm
|
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
|
--cap-drop=ALL
|
|
--network={{ matrix_docker_network }}
|
|
--mount type=bind,src={{ matrix_appservice_irc_data_path }},dst=/data
|
|
--entrypoint=/bin/sh
|
|
{{ matrix_appservice_irc_docker_image }}
|
|
-c
|
|
'/usr/local/bin/node /app/lib/scripts/migrate-db-to-pgres.js --dbdir /data --privateKey /data/passkey.pem --connectionString {{ matrix_appservice_irc_database_connection_string }}'
|
|
register: matrix_appservice_irc_import_nedb_to_postgres_result
|
|
changed_when: matrix_appservice_irc_import_nedb_to_postgres_result.rc == 0
|
|
|
|
- name: Archive NeDB database files
|
|
ansible.builtin.command:
|
|
cmd: "mv {{ matrix_appservice_irc_data_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}.backup"
|
|
with_items:
|
|
- rooms.db
|
|
- users.db
|
|
register: matrix_appservice_irc_import_nedb_to_postgres_move_result
|
|
changed_when: matrix_appservice_irc_import_nedb_to_postgres_move_result.rc == 0
|
|
|
|
- name: Inject result
|
|
ansible.builtin.set_fact:
|
|
matrix_playbook_runtime_results: |
|
|
{{
|
|
matrix_playbook_runtime_results | default([])
|
|
+
|
|
[
|
|
"NOTE: Your appservice-irc database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_irc_data_path }}/*.db` to `{{ matrix_appservice_irc_data_path }}/*.db.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete these files."
|
|
]
|
|
}}
|