mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2024-11-13 19:00:14 +00:00
410a915a8a
This paves the way for installing other roles into `roles/galaxy` using `ansible-galaxy`, similar to how it's done in: - https://github.com/spantaleev/gitea-docker-ansible-deploy - https://github.com/spantaleev/nextcloud-docker-ansible-deploy In the near future, we'll be removing a lot of the shared role code from here and using upstream roles for it. Some of the core `matrix-*` roles have already been extracted out into other reusable roles: - https://github.com/devture/com.devture.ansible.role.postgres - https://github.com/devture/com.devture.ansible.role.systemd_docker_base - https://github.com/devture/com.devture.ansible.role.timesync - https://github.com/devture/com.devture.ansible.role.vars_preserver - https://github.com/devture/com.devture.ansible.role.playbook_runtime_messages - https://github.com/devture/com.devture.ansible.role.playbook_help We just need to migrate to those.
76 lines
4.0 KiB
YAML
76 lines
4.0 KiB
YAML
---
|
|
|
|
# This utility aims to determine if there is some existing Postgres version in use or not.
|
|
# If there is, it also tries to detect the Docker image that corresponds to that version.
|
|
#
|
|
# This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible
|
|
# to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html
|
|
|
|
|
|
- name: Fail detection if expectation fails (Postgres not enabled)
|
|
ansible.builtin.fail:
|
|
msg: "Trying to detect the version of the built-in Postgres server, but Postgres installation is not enabled (`matrix_postgres_enabled: false`)"
|
|
when: not matrix_postgres_enabled
|
|
|
|
- name: Initialize Postgres version determination variables (default to empty)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detection_pg_version_path: "{{ matrix_postgres_data_path }}/PG_VERSION"
|
|
matrix_postgres_detected_existing: false
|
|
matrix_postgres_detected_version: ""
|
|
matrix_postgres_detected_version_corresponding_docker_image: ""
|
|
|
|
- name: Determine existing Postgres version (check PG_VERSION file)
|
|
ansible.builtin.stat:
|
|
path: "{{ matrix_postgres_detection_pg_version_path }}"
|
|
register: result_pg_version_stat
|
|
|
|
- ansible.builtin.set_fact:
|
|
matrix_postgres_detected_existing: true
|
|
when: "result_pg_version_stat.stat.exists"
|
|
|
|
- name: Determine existing Postgres version (read PG_VERSION file)
|
|
ansible.builtin.slurp:
|
|
src: "{{ matrix_postgres_detection_pg_version_path }}"
|
|
register: result_pg_version
|
|
when: matrix_postgres_detected_existing | bool
|
|
|
|
- name: Determine existing Postgres version (make sense of PG_VERSION file)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version: "{{ result_pg_version['content'] | b64decode | replace('\n', '') }}"
|
|
when: matrix_postgres_detected_existing | bool
|
|
|
|
- name: Determine corresponding Docker image to detected version (assume default of latest)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_latest }}"
|
|
when: "matrix_postgres_detected_version != ''"
|
|
|
|
- name: Determine corresponding Docker image to detected version (use 9.x, if detected)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v9 }}"
|
|
when: "matrix_postgres_detected_version.startswith('9.')"
|
|
|
|
- name: Determine corresponding Docker image to detected version (use 10.x, if detected)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v10 }}"
|
|
when: "matrix_postgres_detected_version == '10' or matrix_postgres_detected_version.startswith('10.')"
|
|
|
|
- name: Determine corresponding Docker image to detected version (use 11.x, if detected)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v11 }}"
|
|
when: "matrix_postgres_detected_version == '11' or matrix_postgres_detected_version.startswith('11.')"
|
|
|
|
- name: Determine corresponding Docker image to detected version (use 12.x, if detected)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v12 }}"
|
|
when: "matrix_postgres_detected_version == '12' or matrix_postgres_detected_version.startswith('12.')"
|
|
|
|
- name: Determine corresponding Docker image to detected version (use 13.x, if detected)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v13 }}"
|
|
when: "matrix_postgres_detected_version == '13' or matrix_postgres_detected_version.startswith('13.')"
|
|
|
|
- name: Determine corresponding Docker image to detected version (use 14.x, if detected)
|
|
ansible.builtin.set_fact:
|
|
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v14 }}"
|
|
when: "matrix_postgres_detected_version == '14' or matrix_postgres_detected_version.startswith('14.')"
|