--- - name: Diagnose Gitea Bad Gateway Issue hosts: production gather_facts: yes become: no vars: gitea_stack_path: "{{ stacks_base_path }}/gitea" tasks: - name: Check if Gitea stack directory exists stat: path: "{{ gitea_stack_path }}" register: gitea_stack_dir - name: Display Gitea stack directory status debug: msg: "Gitea stack path: {{ gitea_stack_path }} - Exists: {{ gitea_stack_dir.stat.exists }}" - name: Check Gitea container status shell: | cd {{ gitea_stack_path }} echo "=== Gitea Container Status ===" docker compose ps 2>&1 || echo "Could not check container status" args: executable: /bin/bash register: gitea_status ignore_errors: yes failed_when: false when: gitea_stack_dir.stat.exists - name: Display Gitea container status debug: msg: "{{ gitea_status.stdout_lines }}" when: gitea_stack_dir.stat.exists - name: Check if Gitea container is running shell: | docker ps --filter name=gitea --format "{{ '{{' }}.Names{{ '}}' }}: {{ '{{' }}.Status{{ '}}' }}" register: gitea_running ignore_errors: yes failed_when: false - name: Display Gitea running status debug: msg: "{{ gitea_running.stdout_lines if gitea_running.stdout else 'Gitea container not found' }}" - name: Check Gitea logs (last 50 lines) shell: | cd {{ gitea_stack_path }} echo "=== Gitea Logs (Last 50 lines) ===" docker compose logs --tail=50 gitea 2>&1 || echo "Could not read Gitea logs" args: executable: /bin/bash register: gitea_logs ignore_errors: yes failed_when: false when: gitea_stack_dir.stat.exists - name: Display Gitea logs debug: msg: "{{ gitea_logs.stdout_lines }}" when: gitea_stack_dir.stat.exists - name: Check Gitea container health shell: | docker inspect gitea --format '{{ '{{' }}.State.Health.Status{{ '}}' }}' 2>&1 || echo "Could not check health" register: gitea_health ignore_errors: yes failed_when: false - name: Display Gitea health status debug: msg: "Gitea health: {{ gitea_health.stdout }}" - name: Test Gitea health endpoint from container shell: | docker exec gitea curl -f http://localhost:3000/api/healthz 2>&1 || echo "Health check failed" register: gitea_internal_health ignore_errors: yes failed_when: false - name: Display internal health check result debug: msg: "{{ gitea_internal_health.stdout_lines }}" - name: Check if Gitea is reachable from Traefik network shell: | docker exec traefik curl -f http://gitea:3000/api/healthz 2>&1 || echo "Could not reach Gitea from Traefik network" register: gitea_from_traefik ignore_errors: yes failed_when: false - name: Display Traefik to Gitea connectivity debug: msg: "{{ gitea_from_traefik.stdout_lines }}" - name: Check Traefik logs for Gitea errors shell: | cd {{ stacks_base_path }}/traefik echo "=== Traefik Logs - Gitea related (Last 30 lines) ===" docker compose logs --tail=100 traefik 2>&1 | grep -i "gitea" | tail -30 || echo "No Gitea-related logs found" args: executable: /bin/bash register: traefik_gitea_logs ignore_errors: yes failed_when: false - name: Display Traefik Gitea logs debug: msg: "{{ traefik_gitea_logs.stdout_lines }}" - name: Check Docker networks shell: | echo "=== Docker Networks ===" docker network ls echo "" echo "=== Traefik Network Details ===" docker network inspect traefik-public 2>&1 | grep -E "(Name|Subnet|Containers|gitea)" || echo "Could not inspect traefik-public network" args: executable: /bin/bash register: network_info ignore_errors: yes failed_when: false - name: Display network info debug: msg: "{{ network_info.stdout_lines }}" - name: Check if Gitea is in traefik-public network shell: | docker network inspect traefik-public 2>&1 | grep -i "gitea" || echo "Gitea not found in traefik-public network" register: gitea_in_network ignore_errors: yes failed_when: false - name: Display Gitea network membership debug: msg: "{{ gitea_in_network.stdout_lines }}" - name: Check Gitea container configuration shell: | echo "=== Gitea Container Labels ===" docker inspect gitea --format '{{ '{{' }}range .Config.Labels{{ '}}' }}{{ '{{' }}.Key{{ '}}' }}={{ '{{' }}.Value{{ '}}' }}{{ '{{' }}\n{{ '}}' }}{{ '{{' }}end{{ '}}' }}' 2>&1 | grep -i traefik || echo "No Traefik labels found" register: gitea_labels ignore_errors: yes failed_when: false - name: Display Gitea labels debug: msg: "{{ gitea_labels.stdout_lines }}" - name: Check Traefik service registration shell: | docker exec traefik wget -qO- http://localhost:8080/api/http/services 2>&1 | grep -i gitea || echo "Gitea service not found in Traefik API" register: traefik_service ignore_errors: yes failed_when: false - name: Display Traefik service registration debug: msg: "{{ traefik_service.stdout_lines }}" - name: Test external Gitea access shell: | echo "=== Testing External Gitea Access ===" curl -k -H "User-Agent: Mozilla/5.0" -s -o /dev/null -w "HTTP Status: %{http_code}\n" https://git.michaelschiemer.de/ 2>&1 || echo "Connection failed" args: executable: /bin/bash register: external_test ignore_errors: yes failed_when: false - name: Display external test result debug: msg: "{{ external_test.stdout_lines }}" - name: Summary debug: msg: - "=== DIAGNOSIS SUMMARY ===" - "1. Check if Gitea container is running" - "2. Check if Gitea is in traefik-public network" - "3. Check Gitea health endpoint (port 3000)" - "4. Check Traefik can reach Gitea" - "5. Check Traefik logs for errors" - "" - "Common issues:" - "- Container not running: Restart with 'docker compose up -d' in {{ gitea_stack_path }}" - "- Not in network: Recreate container or add to network" - "- Health check failing: Check Gitea logs for errors" - "- Traefik can't reach: Check network configuration"