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.
109 lines
3.9 KiB
109 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
|
|
||
7 years ago
|
- name: Determine existing Postgres version (check PG_VERSION file)
|
||
|
stat:
|
||
|
path: "{{ matrix_postgres_data_path }}/PG_VERSION"
|
||
|
register: result_pg_version_stat
|
||
|
|
||
|
- name: Determine existing Postgres version (read PG_VERSION file)
|
||
|
slurp:
|
||
|
src: "{{ matrix_postgres_data_path }}/PG_VERSION"
|
||
|
register: result_pg_version
|
||
|
when: "result_pg_version_stat.stat.exists"
|
||
|
|
||
|
- name: Determine existing Postgres version (default to empty)
|
||
|
set_fact:
|
||
|
pg_version: ""
|
||
|
|
||
|
- name: Determine existing Postgres version (make sense of PG_VERSION file)
|
||
|
set_fact:
|
||
|
pg_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}"
|
||
|
when: "result_pg_version_stat.stat.exists"
|
||
|
|
||
|
- name: Determine Postgres version to use (default to latest)
|
||
|
set_fact:
|
||
6 years ago
|
matrix_docker_image_postgres_to_use: "{{ matrix_docker_image_postgres_latest }}"
|
||
7 years ago
|
|
||
|
- name: Determine Postgres version to use (use 9.x, if detected)
|
||
|
set_fact:
|
||
6 years ago
|
matrix_docker_image_postgres_to_use: "{{ matrix_docker_image_postgres_v9 }}"
|
||
7 years ago
|
when: "pg_version.startswith('9.')"
|
||
|
|
||
7 years ago
|
- debug:
|
||
6 years ago
|
msg: "NOTE: Your setup is on an old Postgres version ({{ matrix_docker_image_postgres_to_use }}), while {{ matrix_docker_image_postgres_latest }} is supported. You can upgrade using --tags=upgrade-postgres"
|
||
|
when: "matrix_docker_image_postgres_to_use != matrix_docker_image_postgres_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_docker_image_postgres_to_use }}"
|
||
7 years ago
|
|
||
|
- name: Ensure Postgres environment variables file created
|
||
|
template:
|
||
|
src: "{{ role_path }}/templates/env/{{ item }}.j2"
|
||
|
dest: "{{ matrix_environment_variables_data_path }}/{{ item }}"
|
||
|
mode: 0640
|
||
|
with_items:
|
||
|
- "env-postgres-pgsql-docker"
|
||
|
- "env-postgres-server-docker"
|
||
|
|
||
|
- 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
|
||
|
|
||
7 years ago
|
#
|
||
|
# Tasks related to setting up an internal postgres server
|
||
|
#
|
||
|
|
||
|
- name: Ensure postgres data path exists
|
||
|
file:
|
||
|
path: "{{ matrix_postgres_data_path }}"
|
||
|
state: directory
|
||
|
mode: 0700
|
||
|
owner: "{{ matrix_user_username }}"
|
||
|
group: "{{ matrix_user_username }}"
|
||
|
when: "not matrix_postgres_use_external"
|
||
|
|
||
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
|
||
7 years ago
|
stat: path="/etc/systemd/system/matrix-postgres.service"
|
||
|
register: matrix_postgres_service_stat
|
||
|
when: matrix_postgres_use_external
|
||
|
|
||
|
- name: Ensure matrix-postgres is stopped
|
||
|
service: name=matrix-postgres state=stopped daemon_reload=yes
|
||
|
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
|
||
7 years ago
|
stat: path="{{ matrix_postgres_data_path }}"
|
||
|
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:
|
||
|
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 that."
|
||
7 years ago
|
when: "matrix_postgres_use_external and matrix_postgres_data_path_stat.stat.exists"
|