--- - name: Set PostgreSQL Production variables for template ansible.builtin.set_fact: postgres_db: "{{ postgresql_production_db_name }}" postgres_user: "{{ postgresql_production_db_user }}" postgres_password: "{{ postgresql_production_db_password }}" backup_retention_days: "{{ postgresql_production_backup_retention_days }}" backup_schedule: "{{ postgresql_production_backup_schedule }}" no_log: yes - name: Validate PostgreSQL Production password is set ansible.builtin.fail: msg: | PostgreSQL Production password is not set! Please ensure vault_db_password is defined in: - {{ vault_file | default('inventory/group_vars/production/vault.yml') }} Or pass it via extra vars: -e "postgresql_production_db_password=your-password" when: (postgresql_production_db_password | default('') | string | trim) == '' - name: Create PostgreSQL Production .env file from vault secrets ansible.builtin.template: src: postgresql.env.j2 dest: "{{ postgresql_production_stack_path }}/.env" mode: '0600' - name: Deploy PostgreSQL Production stack community.docker.docker_compose_v2: project_src: "{{ postgresql_production_stack_path }}" state: present pull: always register: postgresql_production_compose_result ignore_errors: yes - name: Show PostgreSQL Production logs if deployment failed shell: | docker compose -f {{ postgresql_production_stack_path }}/docker-compose.yml logs --tail=50 postgres-production register: postgresql_production_logs changed_when: false failed_when: false when: postgresql_production_compose_result.failed | default(false) - name: Display PostgreSQL Production logs on failure ansible.builtin.debug: msg: "{{ postgresql_production_logs.stdout_lines | default([]) }}" when: postgresql_production_compose_result.failed | default(false) - name: Check PostgreSQL Production container status shell: | docker compose -f {{ postgresql_production_stack_path }}/docker-compose.yml ps postgres-production | grep -Eiq "Up|running|healthy" register: postgresql_production_state changed_when: false until: postgresql_production_state.rc == 0 retries: "{{ ((postgresql_production_wait_timeout | int) + (postgresql_production_wait_interval | int) - 1) // (postgresql_production_wait_interval | int) }}" delay: "{{ postgresql_production_wait_interval | int }}" failed_when: postgresql_production_state.rc != 0 when: not ansible_check_mode - name: Fail if PostgreSQL Production deployment failed ansible.builtin.fail: msg: "PostgreSQL Production stack deployment failed. Check logs above for details." when: postgresql_production_compose_result.failed | default(false) - name: Record PostgreSQL Production deployment facts set_fact: postgresql_production_stack_changed: "{{ postgresql_production_compose_result.changed | default(false) }}" postgresql_production_log_hint: ""