--- - name: Verify Environment Variable Loading hosts: production gather_facts: no become: no vars: application_stack_dest: "{{ app_stack_path | default(stacks_base_path + '/production') }}" application_compose_suffix: "production.yml" tasks: - name: Check if docker-compose.production.yml has env_file with absolute path shell: | grep -A 2 "env_file:" {{ application_stack_dest }}/docker-compose.production.yml | head -5 delegate_to: "{{ inventory_hostname }}" register: env_file_check changed_when: false - name: Display env_file configuration debug: msg: | env_file configuration in docker-compose.production.yml: {{ env_file_check.stdout }} - name: Wait for container to be running pause: seconds: 3 - name: Check all environment variables in queue-worker container shell: | timeout 5 docker compose -f {{ application_stack_dest }}/docker-compose.base.yml -f {{ application_stack_dest }}/docker-compose.{{ application_compose_suffix }} exec -T queue-worker env 2>&1 | grep -E "^DB_|^APP_|^REDIS_" | sort || echo "CONTAINER_NOT_RUNNING" register: all_env_vars changed_when: false failed_when: false ignore_errors: yes retries: 3 delay: 2 - name: Display all environment variables debug: msg: | All DB/APP/REDIS Environment Variables in queue-worker: {{ all_env_vars.stdout }} - name: Test if we can read .env file from container shell: | docker compose -f {{ application_stack_dest }}/docker-compose.base.yml -f {{ application_stack_dest }}/docker-compose.{{ application_compose_suffix }} exec -T queue-worker cat /home/deploy/deployment/stacks/production/.env 2>&1 | head -20 || echo "FILE_NOT_READABLE" register: env_file_read_test changed_when: false failed_when: false ignore_errors: yes - name: Display .env file read test debug: msg: | .env file read test from container: {{ env_file_read_test.stdout }}