diff --git a/deployment/ansible/playbooks/deploy-image.yml b/deployment/ansible/playbooks/deploy-image.yml index 3a3a5200..b0650339 100644 --- a/deployment/ansible/playbooks/deploy-image.yml +++ b/deployment/ansible/playbooks/deploy-image.yml @@ -259,6 +259,45 @@ failed_when: false changed_when: compose_update_alt.changed | default(false) + # Ensure PostgreSQL Staging Stack is running (creates postgres-staging-internal network) + - name: Check if PostgreSQL Staging Stack directory exists + ansible.builtin.stat: + path: "{{ stacks_base_path | default('/home/deploy/deployment/stacks') }}/postgresql-staging/docker-compose.yml" + register: postgres_staging_compose_exists + changed_when: false + when: deployment_environment | default('') == 'staging' + + - name: Check if PostgreSQL Staging Stack is running + ansible.builtin.shell: | + cd {{ stacks_base_path | default('/home/deploy/deployment/stacks') }}/postgresql-staging + docker compose ps --format json 2>/dev/null | grep -q '"State":"running"' && echo "RUNNING" || echo "NOT_RUNNING" + register: postgres_staging_status + changed_when: false + failed_when: false + when: + - deployment_environment | default('') == 'staging' + - postgres_staging_compose_exists.stat.exists | default(false) | bool + + - name: Start PostgreSQL Staging Stack if not running + ansible.builtin.shell: | + cd {{ stacks_base_path | default('/home/deploy/deployment/stacks') }}/postgresql-staging + docker compose up -d + register: postgres_staging_start + changed_when: postgres_staging_start.rc == 0 + when: + - deployment_environment | default('') == 'staging' + - postgres_staging_compose_exists.stat.exists | default(false) | bool + - postgres_staging_status.stdout | default('') == 'NOT_RUNNING' + + - name: Wait for PostgreSQL Staging Stack to be ready + ansible.builtin.wait_for: + timeout: 30 + delay: 2 + when: + - deployment_environment | default('') == 'staging' + - postgres_staging_start.changed | default(false) | bool + + # Extract and create external networks (fallback if PostgreSQL Stack doesn't create them) - name: Extract external networks from docker-compose files ansible.builtin.shell: | cd {{ application_code_dest }} @@ -272,7 +311,7 @@ changed_when: false failed_when: false - - name: Extract external network names (with name: field) + - name: "Extract external network names (with name field)" ansible.builtin.shell: | cd {{ application_code_dest }} grep -A 2 "external: true" docker-compose.base.yml docker-compose.{{ application_compose_suffix }} 2>/dev/null | \ @@ -294,6 +333,8 @@ {%- set final_networks = (all_networks + default_networks) | unique | list -%} {{ final_networks }} + # Create external networks (fallback if they weren't created by their respective stacks) + # Note: This is a fallback - ideally networks are created by their stacks (e.g., postgres-staging-internal by PostgreSQL Staging Stack) - name: Ensure Docker networks exist community.docker.docker_network: name: "{{ item }}"