Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(postgresql): support multiple versions #207

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions roles/postgresql/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
register: "postgresql_user_res"
tags: ["prepare", "prepare-postgresql", "deploy", "deploy-postgresql"]

- name: "Ensure PostgreSQL container image is pulled"
community.docker.docker_image:
name: "{{ postgresql_container_image_reference }}"
force_source: "{{ postgresql_container_pull }}"
source: "pull"
state: "present"
tags: ["prepare", "prepare-postgresql"]

- name: "Check if postgresql_data_path exists"
stat:
path: "{{ postgresql_data_path }}"
Expand All @@ -29,6 +21,58 @@
register: "find_postgresql_data_path"
tags: ["prepare", "prepare-postgresql"]

- name: "Check if container {{ postgresql_container_name }} already exists on host"
community.docker.docker_container_info:
name: "{{ postgresql_container_name }}"
register: "postgresql_active_container"
tags: ["prepare", "prepare-postgresql"]

- name: "Set postgresql_active_container_version"
ansible.builtin.set_fact:
postgresql_active_container_version: >-2
{{
postgresql_active_container.container.Config.Env
| select('search', '^PG_VERSION=')
| first
| split('=')
| last
| string
}}
when: "postgresql_active_container.exists"
tags: ["prepare", "prepare-postgresql"]

- name: "Prevent major version update, use version of existing container instead"
ansible.builtin.set_fact:
postgresql_container_version: "{{ postgresql_active_container_version }}"
when:
- "postgresql_active_container.exists"
- "(postgresql_container_version | int) != (postgresql_active_container_version | int)"
tags: ["prepare", "prepare-postgresql"]

- name: "Ensure image {{ postgresql_container_image_reference }} is pulled"
community.docker.docker_image:
name: "{{ postgresql_container_image_reference }}"
force_source: "{{ postgresql_container_pull }}"
source: "pull"
state: "present"
register: "postgresql_image_pulled"
tags: ["prepare", "prepare-postgresql"]
jcgruenhage marked this conversation as resolved.
Show resolved Hide resolved

- name: "Set container version label to version of pulled image"
ansible.builtin.set_fact:
postgresql_container_labels_base:
version: >-2
{{
postgresql_image_pulled.image.Config.Env
| select('search', '^PG_VERSION=')
| first
| split('=')
| last
| string
}}
when: "postgresql_image_pulled.image.Config is defined"
tags: ["prepare", "prepare-postgresql"]

- name: "Initialize"
include_tasks: "initialize.yml"
when: >-
Expand Down
Loading