2017-07-31 20:07:30 +00:00
---
2017-09-08 13:53:24 +00:00
#
# Generic tasks, no matter what kind of server we're using (internal/external)
#
2017-07-31 20:07:30 +00:00
2019-01-12 15:53:00 +00:00
- import_tasks : "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2019-01-12 15:53:00 +00:00
- import_tasks : "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2018-05-28 11:47:09 +00:00
2019-01-01 11:31:01 +00:00
# If we have found an existing version (installed from before), we use its corresponding Docker image.
# If not, we install using the latest Postgres.
#
# Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`).
- set_fact :
matrix_postgres_docker_image_to_use : "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}"
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2018-11-01 07:48:20 +00:00
2019-01-01 11:31:01 +00:00
- name : Warn if on an old version of Postgres
debug :
2018-11-01 06:46:47 +00:00
msg : "NOTE: Your setup is on an old Postgres version ({{ matrix_postgres_docker_image_to_use }}), while {{ matrix_postgres_docker_image_latest }} is supported. You can upgrade using --tags=upgrade-postgres"
2019-05-21 15:25:59 +00:00
when : "matrix_postgres_enabled|bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
2018-05-28 17:40:42 +00:00
2017-09-08 13:53:24 +00:00
# Even if we don't run the internal server, we still need this for running the CLI
2017-07-31 20:07:30 +00:00
- name : Ensure postgres Docker image is pulled
docker_image :
2018-11-01 06:46:47 +00:00
name : "{{ matrix_postgres_docker_image_to_use }}"
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2017-07-31 20:07:30 +00:00
2019-01-12 15:53:00 +00:00
# We always create these directories, even if an external Postgres is used,
# because we store environment variable files there.
- name : Ensure Postgres paths exist
file :
path : "{{ item }}"
state : directory
mode : 0700
owner : "{{ matrix_user_username }}"
group : "{{ matrix_user_username }}"
with_items :
- "{{ matrix_postgres_base_path }}"
- "{{ matrix_postgres_data_path }}"
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2019-01-12 15:53:00 +00:00
2017-07-31 20:07:30 +00:00
- name : Ensure Postgres environment variables file created
template :
2019-01-12 15:53:00 +00:00
src : "{{ role_path }}/templates/{{ item }}.j2"
dest : "{{ matrix_postgres_base_path }}/{{ item }}"
2017-07-31 20:07:30 +00:00
mode : 0640
with_items :
2019-01-12 15:53:00 +00:00
- "env-postgres-psql"
- "env-postgres-server"
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2017-07-31 20:07:30 +00:00
- name : Ensure matrix-postgres-cli script created
template :
src : "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
dest : "/usr/local/bin/matrix-postgres-cli"
mode : 0750
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2017-07-31 20:07:30 +00:00
2018-11-28 10:02:15 +00:00
- name : Ensure matrix-make-user-admin script created
template :
src : "{{ role_path }}/templates/usr-local-bin/matrix-make-user-admin.j2"
dest : "/usr/local/bin/matrix-make-user-admin"
mode : 0750
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2018-11-28 10:02:15 +00:00
2017-09-08 13:53:24 +00:00
#
# Tasks related to setting up an internal postgres server
#
2017-07-31 20:07:30 +00:00
- name : Ensure matrix-postgres.service installed
template :
src : "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
dest : "/etc/systemd/system/matrix-postgres.service"
2017-09-08 13:53:24 +00:00
mode : 0644
2019-03-03 09:55:15 +00:00
register : matrix_postgres_systemd_service_result
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool
2017-09-08 13:53:24 +00:00
2019-03-03 09:55:15 +00:00
- name : Ensure systemd reloaded after matrix-postgres.service installation
service :
daemon_reload : yes
2019-05-21 15:25:59 +00:00
when : "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed"
2019-03-03 09:55:15 +00:00
2017-09-08 13:53:24 +00:00
#
# Tasks related to getting rid of the internal postgres server (if it was previously enabled)
#
2017-09-11 20:50:14 +00:00
- name : Check existence of matrix-postgres service
2019-01-07 22:35:35 +00:00
stat :
path : "/etc/systemd/system/matrix-postgres.service"
2017-09-08 13:53:24 +00:00
register : matrix_postgres_service_stat
2019-05-21 15:25:59 +00:00
when : "not matrix_postgres_enabled|bool"
2017-09-08 13:53:24 +00:00
- name : Ensure matrix-postgres is stopped
2019-01-07 22:35:35 +00:00
service :
name : matrix-postgres
state : stopped
daemon_reload : yes
2019-05-21 15:25:59 +00:00
when : "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
2017-09-08 13:53:24 +00:00
- name : Ensure matrix-postgres.service doesn't exist
file :
path : "/etc/systemd/system/matrix-postgres.service"
state : absent
2019-05-21 15:25:59 +00:00
when : "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
2017-09-08 13:53:24 +00:00
2019-03-03 09:55:15 +00:00
- name : Ensure systemd reloaded after matrix-postgres.service removal
service :
daemon_reload : yes
2019-05-21 15:25:59 +00:00
when : "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
2019-03-03 09:55:15 +00:00
2017-09-11 20:50:14 +00:00
- name : Check existence of matrix-postgres local data path
2019-01-07 22:35:35 +00:00
stat :
path : "{{ matrix_postgres_data_path }}"
2017-09-08 13:53:24 +00:00
register : matrix_postgres_data_path_stat
2019-05-21 15:25:59 +00:00
when : "not matrix_postgres_enabled|bool"
2017-09-08 13:53:24 +00:00
# We just want to notify the user. Deleting data is too destructive.
- name : Notify if matrix-postgres local data remains
debug :
2019-01-16 16:05:48 +00:00
msg : "Note: You are not using a local PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_data_path }}`. Feel free to delete it."
2019-05-21 15:25:59 +00:00
when : "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists"
2019-04-30 13:30:26 +00:00
- name : Ensure matrix-postgres-update-user-password-hash script created
template :
src : "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2"
dest : "/usr/local/bin/matrix-postgres-update-user-password-hash"
mode : 0750
2019-05-21 15:25:59 +00:00
when : matrix_postgres_enabled|bool