mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
The gateway could reach exactly one remote provider, through a bare
OPENROUTER_API_KEY group_var with an empty-string default and an `{% if %}`
around a single hardcoded model entry. OpenAI and Anthropic had no path at all.
All three are now declared in roles/svc-ai-litellm/meta/secrets.yml, which
mapping.py already calls the application config schema, so a key lands at
applications.svc-ai-litellm.secrets.credentials.<provider>_api_key like every
other credential. Each carries the `type` and `regex` its value must satisfy and
defaults to the central API.<provider>.api_key block, which keeps one
operator-facing place to fill a provider in while the role owns the shape.
type and regex had to become real to be worth declaring. 192 `validation:`
blocks sit in the role schemas today and not one line of Python enforces them,
so a `regex` would have joined a pile of decoration. validate_supplied_value
now runs on every path a value arrives from outside — the --set override, a
value already in the inventory, and the value standing next to a `default:`.
A generated value stays exempt because the algorithm that produced it is named
by the same schema and generate_value takes no schema argument. min_length is
deliberately left unenforced: the generators ignore it, so holding them to it
would fail where nothing is wrong.
The pattern is written for the paste, not for the vendor. OpenAI moved issuance
from sk- to sk-proj- without notice and Anthropic issues sk-ant-api03-; a schema
pinning a prefix would reject a valid key and abort inventory creation. `\S{20,}`
accepts every form those three issue today and one nobody has announced, and
rejects a trailing newline, an embedded space, a truncated copy and a
<placeholder>. A key pasted into the wrong provider's slot is caught at deploy
instead, where the route it publishes answers nothing.
The gateway iterates one LITELLM_REMOTE_BACKENDS list instead of three `{% if %}`
blocks; config.yaml.j2 and env.j2 read the same list and selectattr('key')
decides. LITELLM_CHAT_MODEL falls back to the first configured remote alias
rather than to a hardcoded openrouter/auto.
For CI the keys travel as INFINITO_API_{OPENAI,ANTHROPIC,OPENROUTER}_KEY through
default.env, the passthrough allowlist, the infinito service in compose.yml, the
workflow env block and the development inventory. The compose leg is not
optional: the env lint rejected the change without it, because a key the
inventory reads but compose does not forward resolves to empty inside the
container with no error. The workflow reads `secrets.X || vars.X` so a variable
works as asked while a secret wins, which matters because a variable is not
masked and the development inventory sets MASK_CREDENTIALS_IN_LOGS: false.
An unset key is not an error anywhere: the provider's routes stay unpublished
and the CLI test asserts their absence rather than skipping.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
136 lines
5.5 KiB
YAML
136 lines
5.5 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: "🔍 Resolve {{ application_id }} hosting node + container id"
|
|
ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}"
|
|
vars:
|
|
resolve_service_key: "{{ entity_name }}"
|
|
resolve_output_prefix: MATTERMOST_AI
|
|
resolve_compose_cid: "{{ MATTERMOST_CONTAINER_ADDRESS }}"
|
|
resolve_converge_retries: 120
|
|
resolve_converge_delay: 5
|
|
|
|
- name: "🧩 Mattermost | Activate the prepackaged Agents plugin"
|
|
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/agents/enable.yml"
|
|
vars:
|
|
mattermost_agents_cid: "{{ MATTERMOST_AI_LOCAL_CID }}"
|
|
mattermost_agents_node: "{{ MATTERMOST_AI_HOST_NODE }}"
|
|
|
|
- name: "🔎 Mattermost | Compare the stored Agents config to the contract"
|
|
database_query:
|
|
config: "{{ lookup('database', application_id) }}"
|
|
query_file: "{{ role_path }}/files/sql/select/ai/service.sql"
|
|
named_args:
|
|
service: "{{ MATTERMOST_LITELLM_SERVICE | to_json }}"
|
|
bot: "{{ MATTERMOST_LITELLM_BOT | to_json }}"
|
|
expect_rows: true
|
|
mask_values: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
|
register: mattermost_ai_state
|
|
retries: 60
|
|
delay: 5
|
|
until: mattermost_ai_state.rows | default([]) | length > 0
|
|
changed_when: false
|
|
delegate_to: "{{ STACK_HOST }}"
|
|
run_once: true
|
|
|
|
- name: "🤖 Mattermost | Point the Agents bot at the platform gateway"
|
|
when: (mattermost_ai_state.rows[0][0] | trim) != 'converged'
|
|
database_query:
|
|
config: "{{ lookup('database', application_id) }}"
|
|
query_file: "{{ role_path }}/files/sql/update/ai/service.sql"
|
|
named_args:
|
|
service: "{{ MATTERMOST_LITELLM_SERVICE | to_json }}"
|
|
bot: "{{ MATTERMOST_LITELLM_BOT | to_json }}"
|
|
mask_values: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
|
changed_when: true
|
|
delegate_to: "{{ STACK_HOST }}"
|
|
run_once: true
|
|
|
|
- name: "🤖 Mattermost | Retarget the migrated agent row at the gateway"
|
|
database_query:
|
|
config: "{{ lookup('database', application_id) }}"
|
|
query_file: "{{ role_path }}/files/sql/update/ai/agent.sql"
|
|
named_args:
|
|
bot: "{{ MATTERMOST_LITELLM_BOT | to_json }}"
|
|
mask_values: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
|
changed_when: true
|
|
delegate_to: "{{ STACK_HOST }}"
|
|
run_once: true
|
|
|
|
- name: "🔁 Mattermost | Cycle the Agents plugin so it adopts the merged config"
|
|
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/agents/reload.yml"
|
|
vars:
|
|
mattermost_agents_cid: "{{ MATTERMOST_AI_LOCAL_CID }}"
|
|
mattermost_agents_node: "{{ MATTERMOST_AI_HOST_NODE }}"
|
|
|
|
- name: "🔄 Mattermost | Carry the merged Agents config to every replica"
|
|
ansible.builtin.command: >-
|
|
container service update --force
|
|
{{ lookup('container_service', application_id, entity_name) }}
|
|
register: mattermost_agents_swarm_update
|
|
changed_when: mattermost_agents_swarm_update.rc == 0
|
|
become: true
|
|
delegate_to: "{{ STACK_HOST }}"
|
|
run_once: true
|
|
when:
|
|
- DEPLOYMENT_MODE == 'swarm'
|
|
- IS_STACK_HOST | bool
|
|
|
|
- name: "⏳ Mattermost | Wait until every replica is back on the merged config"
|
|
ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml') }}"
|
|
vars:
|
|
wait_service_key: "{{ entity_name }}"
|
|
|
|
- name: "🔎 Mattermost | Re-read the stored Agents service and bot"
|
|
database_query:
|
|
config: "{{ lookup('database', application_id) }}"
|
|
query_file: "{{ role_path }}/files/sql/select/ai/service.sql"
|
|
named_args:
|
|
service: "{{ MATTERMOST_LITELLM_SERVICE | to_json }}"
|
|
bot: "{{ MATTERMOST_LITELLM_BOT | to_json }}"
|
|
expect_rows: true
|
|
mask_values: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
|
register: mattermost_ai_state_final
|
|
changed_when: false
|
|
delegate_to: "{{ STACK_HOST }}"
|
|
run_once: true
|
|
|
|
- name: "🛑 Refuse an Agents configuration that does not match the gateway contract"
|
|
ansible.builtin.assert:
|
|
that:
|
|
- (mattermost_ai_state_final.rows[0][0] | trim) == 'converged'
|
|
- (LITELLM_CHAT_MODEL | trim) | length > 0
|
|
fail_msg: >-
|
|
The Agents plugin still stores a service or bot that differs from the
|
|
deployed gateway contract ({{ MATTERMOST_LITELLM_BASE_URL }},
|
|
model {{ LITELLM_CHAT_MODEL }}), so prompts would leave the deployment,
|
|
use a model the gateway does not serve, or carry a stale virtual key.
|
|
An empty model means the gateway serves none: neither svc-ai-ollama nor
|
|
svc-ai-lmstudio is in this deployment and no remote provider key is set.
|
|
|
|
- name: "🔎 Mattermost | Wait for the Agents plugin to provision its bot account"
|
|
database_query:
|
|
config: "{{ lookup('database', application_id) }}"
|
|
query_file: "{{ role_path }}/files/sql/select/ai/bot-user.sql"
|
|
named_args:
|
|
bot_name: "{{ MATTERMOST_LITELLM_BOT_NAME }}"
|
|
expect_rows: true
|
|
register: mattermost_ai_bot_final
|
|
retries: 60
|
|
delay: 5
|
|
until: (mattermost_ai_bot_final.rows[0][0] | int) > 0
|
|
changed_when: false
|
|
delegate_to: "{{ STACK_HOST }}"
|
|
run_once: true
|
|
|
|
- name: "🛑 Refuse an Agents integration whose bot account was never created"
|
|
ansible.builtin.assert:
|
|
that:
|
|
- (mattermost_ai_bot_final.rows[0][0] | int) > 0
|
|
fail_msg: >-
|
|
The Agents plugin never created the '{{ MATTERMOST_LITELLM_BOT_NAME }}'
|
|
bot account, so no Mattermost surface can address the gateway. The merged
|
|
config row alone does not provision the account; only the plugin's
|
|
EnsureBots run on activation does.
|