80 lines
3.2 KiB
YAML
80 lines
3.2 KiB
YAML
---
|
|
- name: Fix Nginx Upstream Configuration
|
|
hosts: production
|
|
gather_facts: yes
|
|
become: no
|
|
|
|
tasks:
|
|
- name: Check which nginx config files exist
|
|
shell: |
|
|
cd ~/deployment/stacks/staging
|
|
echo "=== Check nginx config files ==="
|
|
docker compose exec -T staging-nginx find /etc/nginx -name "*.conf" -type f 2>&1 | head -20
|
|
echo ""
|
|
echo "=== Check sites-enabled ==="
|
|
docker compose exec -T staging-nginx ls -la /etc/nginx/sites-enabled/ 2>&1 || echo "sites-enabled not found"
|
|
echo ""
|
|
echo "=== Check sites-available ==="
|
|
docker compose exec -T staging-nginx ls -la /etc/nginx/sites-available/ 2>&1 || echo "sites-available not found"
|
|
echo ""
|
|
echo "=== Check nginx.conf includes ==="
|
|
docker compose exec -T staging-nginx grep -E "include|conf.d|sites" /etc/nginx/nginx.conf 2>&1 | head -10
|
|
args:
|
|
executable: /bin/bash
|
|
register: nginx_config_check
|
|
ignore_errors: yes
|
|
failed_when: false
|
|
|
|
- name: Display nginx config check
|
|
debug:
|
|
msg: "{{ nginx_config_check.stdout_lines }}"
|
|
|
|
- name: Find all fastcgi_pass directives
|
|
shell: |
|
|
cd ~/deployment/stacks/staging
|
|
echo "=== Search for fastcgi_pass in all config files ==="
|
|
docker compose exec -T staging-nginx grep -r "fastcgi_pass" /etc/nginx/ 2>&1 || echo "Could not search"
|
|
args:
|
|
executable: /bin/bash
|
|
register: fastcgi_pass_search
|
|
ignore_errors: yes
|
|
failed_when: false
|
|
|
|
- name: Display fastcgi_pass search
|
|
debug:
|
|
msg: "{{ fastcgi_pass_search.stdout_lines }}"
|
|
|
|
- name: Fix all fastcgi_pass to use staging-app:9000
|
|
shell: |
|
|
cd ~/deployment/stacks/staging
|
|
echo "=== Fix fastcgi_pass in all config files ==="
|
|
docker compose exec -T staging-nginx sh -c "find /etc/nginx -name '*.conf' -type f -exec sed -i 's|fastcgi_pass 127.0.0.1:9000;|fastcgi_pass staging-app:9000;|g' {} \;" || echo "Fix failed"
|
|
docker compose exec -T staging-nginx sh -c "find /etc/nginx -name '*.conf' -type f -exec sed -i 's|fastcgi_pass localhost:9000;|fastcgi_pass staging-app:9000;|g' {} \;" || echo "Fix failed"
|
|
docker compose exec -T staging-nginx sh -c "find /etc/nginx -name '*.conf' -type f -exec sed -i 's|fastcgi_pass php-upstream;|fastcgi_pass staging-app:9000;|g' {} \;" || echo "Note: php-upstream should stay as is"
|
|
echo "=== Verify fix ==="
|
|
docker compose exec -T staging-nginx grep -r "fastcgi_pass" /etc/nginx/ 2>&1 | grep -v "staging-app" || echo "All fastcgi_pass now use staging-app"
|
|
args:
|
|
executable: /bin/bash
|
|
register: fix_result
|
|
ignore_errors: yes
|
|
failed_when: false
|
|
|
|
- name: Display fix result
|
|
debug:
|
|
msg: "{{ fix_result.stdout_lines }}"
|
|
|
|
- name: Reload nginx to apply changes
|
|
shell: |
|
|
cd ~/deployment/stacks/staging
|
|
docker compose exec -T staging-nginx nginx -t 2>&1 || echo "Config test failed"
|
|
docker compose restart staging-nginx || echo "Restart failed"
|
|
args:
|
|
executable: /bin/bash
|
|
register: nginx_reload
|
|
ignore_errors: yes
|
|
failed_when: false
|
|
|
|
- name: Display nginx reload result
|
|
debug:
|
|
msg: "{{ nginx_reload.stdout_lines }}"
|