---
- include_tasks: utils/once/flag.yml
- name: "β¬οΈ POSTGRES | Bring an older cluster in the data volume to the pinned major"
include_tasks: upgrade/prepare.yml
- name: "π§ Setup container network for {{ application_id }}"
include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/network/routine.yml') }}"
vars:
compose_handlers_flush: true
application_id: "svc-db-postgres"
database_consumer_id: "svc-db-postgres"
- name: π¦ Install 'psycopg2-binary'
include_role:
name: sys-pip-install
vars:
package_name: "psycopg2-binary"
global_install: true
- name: "β³ POSTGRES | Wait until container is running (not restarting)"
ansible.builtin.shell: >
container inspect --type container --format '{{ "{{.State.Status}}" }} {{ "{{.State.Restarting}}" }}' {{ POSTGRES_CONTAINER_ADDRESS }}
register: pg_state
delegate_to: "{{ STACK_HOST }}"
run_once: true
retries: 120
delay: 2
until: >
(pg_state.stdout is search('running')) and
(pg_state.stdout is not search('true'))
changed_when: false
- name: "β
POSTGRES | Confirm SQL works (socket)"
ansible.builtin.shell: >
container exec --user postgres {{ POSTGRES_CONTAINER_ADDRESS }} sh -lc
'psql -U postgres -d postgres -Atc "SELECT 1" >/dev/null'
register: pg_sql_ready
delegate_to: "{{ STACK_HOST }}"
run_once: true
retries: 30
delay: 2
until: pg_sql_ready.rc == 0
changed_when: false
- name: "β
POSTGRES | Ensure postgres superuser password matches inventory"
ansible.builtin.command:
argv:
- bash
- -c
- "{{ lookup('file', 'shell/set_postgres_superuser_password.sh') }}"
- set_postgres_superuser_password.sh
- "{{ POSTGRES_CONTAINER_ADDRESS }}"
- postgres
stdin: "{{ POSTGRES_PASSWORD }}"
expand_argument_vars: false
register: postgres_pw_result
delegate_to: "{{ STACK_HOST }}"
run_once: true
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
changed_when: >
postgres_pw_result.stdout is search('\\[CHANGED\\]')
failed_when: >
postgres_pw_result.rc != 0 or
postgres_pw_result.stdout is search('\\[FAIL\\]')
- name: "π§Ή POSTGRES | Finish an upgrade once the pinned major runs"
include_tasks: upgrade/finalize.yml
when: IS_COMPOSE_MODE