feat(postgresql): prevent major version updates

By default the role will now update PostgreSQL to the latest available minor
version, when only a major version is given, or the version of the deployed
container if postgresql_container_version does not match the major version
of that container.
This commit is contained in:
Sebastian Fleer 2024-02-20 13:42:07 +01:00
parent c668936178
commit b8af3d57f1
No known key found for this signature in database
GPG key ID: C24CB83D52ADE8D6

View file

@ -7,14 +7,6 @@
register: "postgresql_user_res" register: "postgresql_user_res"
tags: ["prepare", "prepare-postgresql", "deploy", "deploy-postgresql"] 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" - name: "Check if postgresql_data_path exists"
stat: stat:
path: "{{ postgresql_data_path }}" path: "{{ postgresql_data_path }}"
@ -29,6 +21,58 @@
register: "find_postgresql_data_path" register: "find_postgresql_data_path"
tags: ["prepare", "prepare-postgresql"] 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"]
- 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" - name: "Initialize"
include_tasks: "initialize.yml" include_tasks: "initialize.yml"
when: >- when: >-