You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.5 KiB
125 lines
4.5 KiB
7 years ago
|
---
|
||
|
|
||
|
- name: Set default postgres_dump_dir, if not provided
|
||
|
set_fact:
|
||
|
postgres_dump_dir: "/tmp"
|
||
|
when: "postgres_dump_dir|default('') == ''"
|
||
|
|
||
|
- name: Set postgres_dump_name, if not provided
|
||
|
set_fact:
|
||
|
postgres_dump_name: "matrix-postgres.out"
|
||
|
when: "postgres_dump_name|default('') == ''"
|
||
|
|
||
6 years ago
|
- name: Set postgres_auto_upgrade_backup_data_path, if not provided
|
||
|
set_fact:
|
||
7 years ago
|
postgres_auto_upgrade_backup_data_path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup"
|
||
6 years ago
|
when: "postgres_auto_upgrade_backup_data_path|default('') == ''"
|
||
7 years ago
|
|
||
6 years ago
|
- name: Set postgres_start_wait_time, if not provided
|
||
|
set_fact:
|
||
|
postgres_start_wait_time: 15
|
||
|
when: "postgres_start_wait_time|default('') == ''"
|
||
|
|
||
7 years ago
|
- name: Fail, if trying to upgrade external Postgres database
|
||
|
fail:
|
||
|
msg: "Your configuration indicates that you're using an external Postgres database. Refusing to try and upgrade that."
|
||
|
when: "matrix_postgres_use_external"
|
||
|
|
||
|
- name: Check Postgres auto-upgrade backup data directory
|
||
|
stat:
|
||
|
path: "{{ postgres_auto_upgrade_backup_data_path }}"
|
||
|
register: result_auto_upgrade_path
|
||
|
|
||
|
- name: Abort, if existing Postgres auto-upgrade data path detected
|
||
|
fail:
|
||
|
msg: "Detected that a left-over {{ postgres_auto_upgrade_backup_data_path }} exists. You should rename it to {{ matrix_postgres_data_path }} if the previous upgrade went wrong, or delete it if it went well."
|
||
|
when: "result_auto_upgrade_path.stat.exists"
|
||
|
|
||
6 years ago
|
- import_tasks: tasks/util/detect_existing_postgres_version.yml
|
||
7 years ago
|
|
||
|
- name: Abort, if no existing Postgres version detected
|
||
6 years ago
|
fail:
|
||
|
msg: "Could not find existing Postgres installation"
|
||
6 years ago
|
when: "not matrix_postgres_detected_existing"
|
||
6 years ago
|
|
||
7 years ago
|
- name: Abort, if already at latest Postgres version
|
||
6 years ago
|
fail:
|
||
|
msg: "You are already running the latest Postgres version supported ({{ matrix_postgres_docker_image_latest }}). Nothing to do"
|
||
6 years ago
|
when: "matrix_postgres_detected_version_corresponding_docker_image == matrix_postgres_docker_image_latest"
|
||
7 years ago
|
|
||
6 years ago
|
- debug:
|
||
6 years ago
|
msg: "Upgrading database from {{ matrix_postgres_detected_version_corresponding_docker_image }} to {{ matrix_postgres_docker_image_latest }}"
|
||
6 years ago
|
|
||
7 years ago
|
- name: Ensure matrix-synapse is stopped
|
||
6 years ago
|
service:
|
||
|
name: matrix-synapse
|
||
|
state: stopped
|
||
7 years ago
|
|
||
|
- name: Ensure matrix-postgres is started
|
||
6 years ago
|
service:
|
||
|
name: matrix-postgres
|
||
|
state: started
|
||
|
daemon_reload: yes
|
||
7 years ago
|
|
||
|
- name: Wait a bit, so that Postgres can start
|
||
|
wait_for:
|
||
6 years ago
|
timeout: "{{ postgres_start_wait_time }}"
|
||
7 years ago
|
delegate_to: 127.0.0.1
|
||
|
become: false
|
||
|
|
||
|
- name: Perform Postgres database dump
|
||
|
command: |
|
||
|
/usr/bin/docker run --rm --name matrix-postgres-dump \
|
||
6 years ago
|
--network={{ matrix_docker_network }} \
|
||
6 years ago
|
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql \
|
||
7 years ago
|
-v {{ postgres_dump_dir }}:/out \
|
||
6 years ago
|
{{ matrix_postgres_detected_version_corresponding_docker_image }} pg_dump -h matrix-postgres {{ matrix_postgres_db_name }} -f /out/{{ postgres_dump_name }}
|
||
7 years ago
|
|
||
|
- name: Ensure matrix-postgres is stopped
|
||
6 years ago
|
service:
|
||
|
name: matrix-postgres
|
||
|
state: stopped
|
||
7 years ago
|
|
||
|
- name: Rename existing Postgres data directory
|
||
|
command: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}"
|
||
|
|
||
|
- debug:
|
||
|
msg: "NOTE: Your Postgres data directory has been moved from `{{ matrix_postgres_data_path }}` to `{{ postgres_auto_upgrade_backup_data_path }}`. In the event of failure, you can move it back and run the playbook with --tags=setup-postgres to restore operation."
|
||
|
|
||
6 years ago
|
- import_tasks: tasks/setup_postgres.yml
|
||
7 years ago
|
|
||
|
- name: Ensure matrix-postgres autoruns and is restarted
|
||
6 years ago
|
service:
|
||
|
name: matrix-postgres
|
||
|
enabled: yes
|
||
|
state: restarted
|
||
|
daemon_reload: yes
|
||
7 years ago
|
|
||
|
- name: Wait a bit, so that Postgres can start
|
||
|
wait_for:
|
||
6 years ago
|
timeout: "{{ postgres_start_wait_time }}"
|
||
7 years ago
|
delegate_to: 127.0.0.1
|
||
|
become: false
|
||
|
|
||
|
- name: Perform Postgres database import
|
||
|
command: |
|
||
|
/usr/bin/docker run --rm --name matrix-postgres-import \
|
||
6 years ago
|
--network={{ matrix_docker_network }} \
|
||
6 years ago
|
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql \
|
||
7 years ago
|
-v {{ postgres_dump_dir }}:/in:ro \
|
||
6 years ago
|
{{ matrix_postgres_docker_image_latest }} psql -v ON_ERROR_STOP=1 -h matrix-postgres -f /in/{{ postgres_dump_name }}
|
||
7 years ago
|
|
||
|
- name: Delete Postgres database dump file
|
||
|
file:
|
||
|
path: "{{ postgres_dump_dir }}/{{ postgres_dump_name }}"
|
||
|
state: absent
|
||
|
|
||
|
- name: Ensure matrix-synapse is started
|
||
6 years ago
|
service:
|
||
|
name: matrix-synapse
|
||
|
state: started
|
||
|
daemon_reload: yes
|
||
7 years ago
|
|
||
|
- debug:
|
||
|
msg: "NOTE: Your old Postgres data directory is preserved at `{{ postgres_auto_upgrade_backup_data_path }}`. You might want to get rid of it once you've confirmed that all is well."
|