--- # Install Composer Dependencies in Application Container - name: Check if composer.json exists ansible.builtin.stat: path: "{{ application_code_dest }}/composer.json" register: composer_json_exists - name: Fail if composer.json is missing ansible.builtin.fail: msg: "composer.json not found at {{ application_code_dest }}/composer.json" when: not composer_json_exists.stat.exists - name: Check if container is running ansible.builtin.shell: | cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} ps {{ application_php_service_name }} --format json register: container_status changed_when: false failed_when: false - name: Display container status ansible.builtin.debug: msg: "Container status: {{ container_status.stdout }}" when: application_show_status | default(true) | bool - name: Fail if container is not running ansible.builtin.fail: msg: | Container '{{ application_php_service_name }}' is not running! The container must be started before installing composer dependencies. This is typically done by the 'deploy-image.yml' playbook which should run before this. To start the container manually: cd {{ application_code_dest }} docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} up -d {{ application_php_service_name }} Note: The container requires environment variables (DB_USERNAME, DB_PASSWORD, etc.) which should be set in a .env file or via docker-compose environment configuration. when: container_status.rc != 0 or '"State":"running"' not in container_status.stdout - name: Install composer dependencies in PHP 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 }} composer install --no-dev --optimize-autoloader --no-interaction register: composer_install changed_when: true failed_when: composer_install.rc != 0 - name: Display composer install output ansible.builtin.debug: msg: | Composer Install Output: stdout: {{ composer_install.stdout }} stderr: {{ composer_install.stderr }} rc: {{ composer_install.rc }} when: - composer_install.rc != 0 - application_show_status | default(true) | bool - 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_restart_workers_after_composer | default(true) | bool - name: Verify vendor/autoload.php exists 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 - name: Display autoload verification ansible.builtin.debug: msg: "vendor/autoload.php: {{ autoload_check.stdout.strip() }}" when: application_show_status | default(true) | bool - name: Fail if autoload.php is missing ansible.builtin.fail: msg: "vendor/autoload.php was not created after composer install" when: "autoload_check.stdout.strip() != 'EXISTS'"