--- # Container Management Tasks (Fix, Recreate, etc.) - name: Check if vendor directory exists on host ansible.builtin.stat: path: "{{ application_code_dest }}/vendor" register: vendor_dir_exists - name: Display vendor directory status ansible.builtin.debug: msg: "vendor directory on host: {{ 'EXISTS' if vendor_dir_exists.stat.exists else 'MISSING' }}" when: application_show_status | default(true) | bool - name: Install composer dependencies in PHP container (if vendor missing) ansible.builtin.shell: | cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} exec -T {{ application_php_service_name }} composer install --no-dev --optimize-autoloader --no-interaction register: composer_install changed_when: true failed_when: composer_install.rc != 0 when: - application_container_action | default('fix') == 'fix' - not vendor_dir_exists.stat.exists - name: Verify vendor/autoload.php exists in container ansible.builtin.shell: | cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} exec -T {{ application_php_service_name }} test -f /var/www/html/vendor/autoload.php && echo "EXISTS" || echo "MISSING" register: autoload_check changed_when: false when: application_container_action | default('fix') == 'fix' - name: Display autoload verification ansible.builtin.debug: msg: "vendor/autoload.php in container: {{ autoload_check.stdout.strip() }}" when: - application_container_action | default('fix') == 'fix' - application_show_status | default(true) | bool - name: Recreate web container with new security settings ansible.builtin.shell: | cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} up -d --force-recreate --no-deps web register: recreate_web changed_when: true when: - application_container_action | default('fix') in ['fix', 'fix-web'] - name: Recreate queue-worker and scheduler containers ansible.builtin.shell: | cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} up -d --force-recreate {{ application_container_target_services | default('queue-worker scheduler') }} register: recreate_containers changed_when: true when: - application_container_action | default('fix') in ['recreate', 'recreate-with-env', 'sync-recreate'] - name: Restart queue-worker and scheduler to pick up vendor directory ansible.builtin.shell: | cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} restart queue-worker scheduler register: restart_workers changed_when: true failed_when: false when: - application_container_action | default('fix') == 'fix' - application_restart_workers_after_composer | default(true) | bool - name: Wait for containers to stabilize ansible.builtin.pause: seconds: "{{ application_container_stabilize_wait | default(5) }}" when: application_container_action | default('fix') in ['fix', 'recreate', 'recreate-with-env', 'sync-recreate'] - name: Get final container status ansible.builtin.shell: | cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} ps {{ application_container_status_services | default('queue-worker web scheduler php') }} register: final_status changed_when: false - name: Display final container status ansible.builtin.debug: msg: | {{ final_status.stdout }} when: application_show_status | default(true) | bool