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.
107 lines
3.9 KiB
107 lines
3.9 KiB
7 years ago
|
---
|
||
|
|
||
7 years ago
|
#
|
||
|
# Generic tasks, no matter what kind of server we're using (internal/external)
|
||
|
#
|
||
7 years ago
|
|
||
6 years ago
|
- import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
|
||
|
|
||
|
- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
|
||
7 years ago
|
|
||
6 years ago
|
# 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 }}"
|
||
6 years ago
|
|
||
6 years ago
|
- name: Warn if on an old version of Postgres
|
||
|
debug:
|
||
6 years ago
|
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"
|
||
|
when: "matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
|
||
7 years ago
|
|
||
7 years ago
|
# Even if we don't run the internal server, we still need this for running the CLI
|
||
7 years ago
|
- name: Ensure postgres Docker image is pulled
|
||
|
docker_image:
|
||
6 years ago
|
name: "{{ matrix_postgres_docker_image_to_use }}"
|
||
7 years ago
|
|
||
6 years ago
|
# 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 }}"
|
||
|
|
||
7 years ago
|
- name: Ensure Postgres environment variables file created
|
||
|
template:
|
||
6 years ago
|
src: "{{ role_path }}/templates/{{ item }}.j2"
|
||
|
dest: "{{ matrix_postgres_base_path }}/{{ item }}"
|
||
7 years ago
|
mode: 0640
|
||
|
with_items:
|
||
6 years ago
|
- "env-postgres-psql"
|
||
|
- "env-postgres-server"
|
||
7 years ago
|
|
||
|
- 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
|
||
|
|
||
6 years ago
|
- 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
|
||
|
|
||
7 years ago
|
#
|
||
|
# Tasks related to setting up an internal postgres server
|
||
|
#
|
||
|
|
||
7 years ago
|
- name: Ensure matrix-postgres.service installed
|
||
|
template:
|
||
|
src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2"
|
||
|
dest: "/etc/systemd/system/matrix-postgres.service"
|
||
7 years ago
|
mode: 0644
|
||
|
when: "not matrix_postgres_use_external"
|
||
|
|
||
|
#
|
||
|
# Tasks related to getting rid of the internal postgres server (if it was previously enabled)
|
||
|
#
|
||
|
|
||
7 years ago
|
- name: Check existence of matrix-postgres service
|
||
6 years ago
|
stat:
|
||
|
path: "/etc/systemd/system/matrix-postgres.service"
|
||
7 years ago
|
register: matrix_postgres_service_stat
|
||
|
when: matrix_postgres_use_external
|
||
|
|
||
|
- name: Ensure matrix-postgres is stopped
|
||
6 years ago
|
service:
|
||
|
name: matrix-postgres
|
||
|
state: stopped
|
||
|
daemon_reload: yes
|
||
7 years ago
|
when: "matrix_postgres_use_external and matrix_postgres_service_stat.stat.exists"
|
||
|
|
||
|
- name: Ensure matrix-postgres.service doesn't exist
|
||
|
file:
|
||
|
path: "/etc/systemd/system/matrix-postgres.service"
|
||
|
state: absent
|
||
|
when: "matrix_postgres_use_external and matrix_postgres_service_stat.stat.exists"
|
||
|
|
||
7 years ago
|
- name: Check existence of matrix-postgres local data path
|
||
6 years ago
|
stat:
|
||
|
path: "{{ matrix_postgres_data_path }}"
|
||
7 years ago
|
register: matrix_postgres_data_path_stat
|
||
|
when: matrix_postgres_use_external
|
||
|
|
||
|
# We just want to notify the user. Deleting data is too destructive.
|
||
|
- name: Notify if matrix-postgres local data remains
|
||
|
debug:
|
||
6 years ago
|
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."
|
||
7 years ago
|
when: "matrix_postgres_use_external and matrix_postgres_data_path_stat.stat.exists"
|