2019-01-01 14:40:48 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# Pre-checks
|
|
|
|
|
2019-01-16 18:05:48 +02:00
|
|
|
- name: Fail if Postgres not enabled
|
|
|
|
fail:
|
|
|
|
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
|
|
|
|
when: "not matrix_postgres_enabled"
|
|
|
|
|
2019-01-01 14:40:48 +02:00
|
|
|
- name: Fail if playbook called incorrectly
|
2019-01-08 00:35:35 +02:00
|
|
|
fail:
|
|
|
|
msg: "The `server_path_postgres_dump` variable needs to be provided to this playbook, via --extra-vars"
|
2019-01-01 14:40:48 +02:00
|
|
|
when: "server_path_postgres_dump is not defined or server_path_postgres_dump.startswith('<')"
|
|
|
|
|
|
|
|
- name: Check if the provided Postgres dump file exists
|
2019-01-08 00:35:35 +02:00
|
|
|
stat:
|
|
|
|
path: "{{ server_path_postgres_dump }}"
|
2019-01-01 14:40:48 +02:00
|
|
|
register: result_server_path_postgres_dump_stat
|
|
|
|
|
|
|
|
- name: Fail if provided Postgres dump file doesn't exists
|
2019-01-08 00:35:35 +02:00
|
|
|
fail:
|
|
|
|
msg: "File cannot be found on the server at {{ server_path_postgres_dump }}"
|
2019-01-01 14:40:48 +02:00
|
|
|
when: not result_server_path_postgres_dump_stat.stat.exists
|
|
|
|
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
|
|
|
|
- name: Set postgres_start_wait_time, if not provided
|
|
|
|
set_fact:
|
|
|
|
postgres_start_wait_time: 15
|
|
|
|
when: "postgres_start_wait_time|default('') == ''"
|
|
|
|
|
2019-01-21 08:34:49 +02:00
|
|
|
- name: Set postgres_import_wait_time, if not provided
|
|
|
|
set_fact:
|
|
|
|
postgres_import_wait_time: "{{ 7 * 86400 }}"
|
|
|
|
when: "postgres_import_wait_time|default('') == ''"
|
|
|
|
|
2019-01-01 14:40:48 +02:00
|
|
|
# Actual import work
|
|
|
|
|
|
|
|
- name: Ensure matrix-postgres is started
|
2019-01-08 00:35:35 +02:00
|
|
|
service:
|
|
|
|
name: matrix-postgres
|
|
|
|
state: started
|
|
|
|
daemon_reload: yes
|
2019-01-01 14:40:48 +02: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
|
|
|
|
|
2019-01-21 07:32:19 +02:00
|
|
|
- import_tasks: tasks/util/detect_existing_postgres_version.yml
|
|
|
|
|
|
|
|
- name: Abort, if no existing Postgres version detected
|
|
|
|
fail:
|
|
|
|
msg: "Could not find existing Postgres installation"
|
|
|
|
when: "not matrix_postgres_detected_existing"
|
|
|
|
|
2019-01-21 08:33:10 +02:00
|
|
|
- name: Generate Postgres database import command
|
|
|
|
set_fact:
|
|
|
|
matrix_postgres_import_command: >-
|
|
|
|
/usr/bin/docker run --rm --name matrix-postgres-import
|
|
|
|
--network={{ matrix_docker_network }}
|
|
|
|
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
|
|
|
|
-v {{ server_path_postgres_dump }}:{{ server_path_postgres_dump }}:ro
|
|
|
|
--entrypoint=/bin/sh
|
|
|
|
{{ matrix_postgres_docker_image_latest }}
|
|
|
|
-c 'cat {{ server_path_postgres_dump }} |
|
|
|
|
{{ 'gunzip |' if server_path_postgres_dump.endswith('.gz') else '' }}
|
|
|
|
psql -v ON_ERROR_STOP=1 -h matrix-postgres'
|
|
|
|
|
|
|
|
- name: Note about Postgres importing alternative
|
|
|
|
debug:
|
|
|
|
msg: >
|
|
|
|
Importing Postgres database using the following command: `{{ matrix_postgres_import_command }}`.
|
|
|
|
If this crashes, you can stop Postgres (`systemctl stop matrix-postgres`),
|
|
|
|
delete its existing data (`rm -rf {{ matrix_postgres_data_path }}/*`), start it again (`systemctl start matrix-postgres`)
|
|
|
|
and manually run the above import command directly on the server.
|
|
|
|
|
2019-01-01 14:40:48 +02:00
|
|
|
- name: Perform Postgres database import
|
2019-01-21 08:33:10 +02:00
|
|
|
command: "{{ matrix_postgres_import_command }}"
|
2019-01-21 08:34:49 +02:00
|
|
|
async: "{{ postgres_import_wait_time }}"
|
|
|
|
poll: 10
|