postgres_password_sync.ymlΒΆ

---
- name: "⏳ Wait until PostgreSQL is ready"
  ansible.builtin.shell: > # nocheck: container-address-quote compose_mode_force role
    container exec -i {{ BBB_POSTGRES_CONTAINER_ADDRESS | quote }}
    pg_isready -h 127.0.0.1 -U postgres
  register: pg_ready
  retries: 20
  delay: 3
  until: pg_ready.rc == 0
  changed_when: false

- name: "⏳ Wait for PostgreSQL to accept SQL after initdb restarts"
  ansible.builtin.shell: > # nocheck: container-address-quote compose_mode_force role
    container exec -i {{ BBB_POSTGRES_CONTAINER_ADDRESS | quote }}
    psql -U postgres -d postgres -tAc "SELECT 1;"
  register: pg_sql_ready
  retries: 30
  delay: 2
  until: pg_sql_ready.rc == 0 and (pg_sql_ready.stdout | trim) == '1'
  changed_when: false

- name: "βœ… Ensure PostgreSQL password matches POSTGRESQL_SECRET"
  no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
  ansible.builtin.shell:
    cmd: > # nocheck: container-address-quote compose_mode_force role
      container exec -i {{ BBB_POSTGRES_CONTAINER_ADDRESS | quote }}
      psql -U postgres -d postgres -v ON_ERROR_STOP=1
    stdin: "ALTER USER postgres WITH PASSWORD '{{ BBB_POSTGRESQL_SECRET | replace(\"'\", \"''\") }}';"
  register: bbb_pg_alter
  retries: 20
  delay: 3
  until: bbb_pg_alter.rc == 0
  changed_when: false