---
- 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: >
IFS= read -r AI_API_KEY && export AI_API_KEY && 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
-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: |-
{{ MOODLE_LITELLM_API_KEY }}
{{ 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 }}"