2017-07-31 20:07:30 +00:00
|
|
|
---
|
|
|
|
|
2019-01-01 13:16:13 +00:00
|
|
|
# Pre-checks
|
|
|
|
|
2019-01-16 16:05:48 +00:00
|
|
|
- name: Fail if Postgres not enabled
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.fail:
|
2019-01-16 16:05:48 +00:00
|
|
|
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
|
2019-05-21 15:25:59 +00:00
|
|
|
when: "not matrix_postgres_enabled|bool"
|
2019-01-16 16:05:48 +00:00
|
|
|
|
2017-07-31 20:07:30 +00:00
|
|
|
- name: Fail if playbook called incorrectly
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.fail:
|
2019-01-07 22:35:35 +00:00
|
|
|
msg: "The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars"
|
2019-01-01 13:16:13 +00:00
|
|
|
when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')"
|
2017-07-31 20:07:30 +00:00
|
|
|
|
|
|
|
- name: Check if the provided SQLite homeserver.db file exists
|
2019-01-07 22:35:35 +00:00
|
|
|
stat:
|
|
|
|
path: "{{ server_path_homeserver_db }}"
|
2019-01-01 13:16:13 +00:00
|
|
|
register: result_server_path_homeserver_db_stat
|
2017-07-31 20:07:30 +00:00
|
|
|
|
|
|
|
- name: Fail if provided SQLite homeserver.db file doesn't exist
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.fail:
|
2019-01-07 22:35:35 +00:00
|
|
|
msg: "File cannot be found on the server at {{ server_path_homeserver_db }}"
|
2019-05-21 15:25:59 +00:00
|
|
|
when: "not result_server_path_homeserver_db_stat.stat.exists"
|
2017-07-31 20:07:30 +00:00
|
|
|
|
|
|
|
|
2019-01-01 13:16:13 +00:00
|
|
|
# Defaults
|
|
|
|
|
|
|
|
- name: Set postgres_start_wait_time, if not provided
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.set_fact:
|
2019-01-01 13:16:13 +00:00
|
|
|
postgres_start_wait_time: 15
|
|
|
|
when: "postgres_start_wait_time|default('') == ''"
|
|
|
|
|
|
|
|
|
|
|
|
# Actual import work
|
2017-07-31 20:07:30 +00:00
|
|
|
|
|
|
|
- name: Ensure matrix-postgres is stopped
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.service:
|
2019-01-07 22:35:35 +00:00
|
|
|
name: matrix-postgres
|
|
|
|
state: stopped
|
2022-02-05 20:32:54 +00:00
|
|
|
daemon_reload: true
|
2017-07-31 20:07:30 +00:00
|
|
|
|
|
|
|
- name: Ensure postgres data is wiped out
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.file:
|
2017-07-31 20:07:30 +00:00
|
|
|
path: "{{ matrix_postgres_data_path }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Ensure postgres data path exists
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.file:
|
2017-07-31 20:07:30 +00:00
|
|
|
path: "{{ matrix_postgres_data_path }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0700
|
|
|
|
owner: "{{ matrix_user_username }}"
|
2020-05-01 17:59:32 +00:00
|
|
|
group: "{{ matrix_user_groupname }}"
|
2017-07-31 20:07:30 +00:00
|
|
|
|
|
|
|
- name: Ensure matrix-postgres is started
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.service:
|
2019-01-07 22:35:35 +00:00
|
|
|
name: matrix-postgres
|
|
|
|
state: restarted
|
2022-02-05 20:32:54 +00:00
|
|
|
daemon_reload: true
|
2017-07-31 20:07:30 +00:00
|
|
|
|
2019-01-01 13:16:13 +00:00
|
|
|
- name: Wait a bit, so that Postgres can start
|
|
|
|
wait_for:
|
|
|
|
timeout: "{{ postgres_start_wait_time }}"
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
become: false
|
2017-07-31 20:07:30 +00:00
|
|
|
|
2019-02-25 08:42:27 +00:00
|
|
|
# We don't use the `docker_container` module, because using it with `cap_drop` requires
|
|
|
|
# a very recent version, which is not available for a lot of people yet.
|
|
|
|
#
|
|
|
|
# Also, some old `docker_container` versions were buggy and would leave containers behind
|
|
|
|
# on failure, which we had to work around to allow retries (by re-running the playbook).
|
|
|
|
- name: Import SQLite database into Postgres
|
2022-07-18 07:39:08 +00:00
|
|
|
ansible.builtin.command: |
|
2019-02-25 08:42:27 +00:00
|
|
|
docker run
|
|
|
|
--rm
|
|
|
|
--name=matrix-synapse-migrate
|
2020-09-01 06:03:06 +00:00
|
|
|
--log-driver=none
|
2019-02-25 08:42:27 +00:00
|
|
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
|
|
|
--cap-drop=ALL
|
|
|
|
--network={{ matrix_docker_network }}
|
|
|
|
--entrypoint=python
|
2020-11-25 08:49:59 +00:00
|
|
|
--mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
|
|
|
|
--mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store
|
|
|
|
--mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db|basename }}
|
2019-02-25 08:42:27 +00:00
|
|
|
{{ matrix_synapse_docker_image }}
|
|
|
|
/usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db|basename }} --postgres-config /data/homeserver.yaml
|