Files
computer-playbook/roles/web-app-moodle/tasks/utils/ai_gateway.yml
kevinveenbirkenbachandClaude Opus 5.5 df214dd00a refactor(web-app-moodle): group the provisioning scripts in files/php/provision
provision_ai_gateway.php and provision_mcp.php shared a prefix inside one
directory, which test_prefix_grouped_files rejects. Both move into
files/php/provision/ as ai_gateway.php and mcp.php, the layout
web-app-n8n already uses for its Python provisioning scripts.

The two lookups that feed the scripts to the container follow, and the
unit test moves to its mirrored path as provision/AiGatewayTest.php.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 01:37:03 +02:00

48 lines
2.1 KiB
YAML

---
- name: "🔐 Verify the gateway contract for {{ application_id }}"
ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/svc-ai-litellm/tasks/utils/consumer_contract.yml') }}"
- name: "🤖 Point the Moodle AI provider instance at the platform gateway"
ansible.builtin.shell: >
container exec -i --user {{ MOODLE_RUNTIME_USER }}
-e MOODLE_CONFIG={{ MOODLE_CONFIG | quote }}
-e AI_PROVIDER_NAME={{ MOODLE_LITELLM_PROVIDER_NAME | quote }}
-e AI_API_KEY={{ MOODLE_LITELLM_API_KEY | quote }}
-e AI_CHAT_ENDPOINT={{ MOODLE_LITELLM_CHAT_ENDPOINT | quote }}
-e AI_CHAT_MODEL={{ LITELLM_CHAT_MODEL | quote }}
-e AI_IMAGE_ENDPOINT={{ MOODLE_LITELLM_IMAGE_ENDPOINT | quote }}
{{ MOODLE_CONTAINER_ADDRESS }} php
args:
stdin: "{{ lookup('file', 'php/provision/ai_gateway.php') }}"
register: moodle_ai_provider
changed_when: false
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
- name: "🤖 Enable the Moodle AI placements"
ansible.builtin.shell: >
container exec --user {{ MOODLE_RUNTIME_USER }} {{ MOODLE_CONTAINER_ADDRESS }}
php {{ [MOODLE_CLI_DIR, 'cfg.php'] | path_join }}
--component={{ item | quote }}
--name=enabled
--set=1
loop: "{{ MOODLE_LITELLM_PLACEMENTS }}"
changed_when: false
- name: "🧹 Purge Moodle caches so the provider picks up its endpoint"
ansible.builtin.shell: >
container exec --user {{ MOODLE_RUNTIME_USER }} {{ MOODLE_CONTAINER_ADDRESS }}
php {{ [MOODLE_CLI_DIR, 'purge_caches.php'] | path_join }}
changed_when: false
- name: "🛑 Refuse a Moodle AI provider that does not answer through the gateway"
ansible.builtin.assert:
that:
- moodle_ai_endpoints | length > 0
- moodle_ai_endpoints | difference([MOODLE_LITELLM_CHAT_ENDPOINT, MOODLE_LITELLM_IMAGE_ENDPOINT]) | length == 0
fail_msg: >-
The Moodle AI provider instance resolves actions to
{{ moodle_ai_endpoints | join(', ') }} instead of
{{ MOODLE_LITELLM_CHAT_ENDPOINT }}, so prompts would leave the deployment.
vars:
moodle_ai_endpoints: "{{ (moodle_ai_provider.stdout_lines | last | from_json).endpoints.values() | unique | list }}"