Ansible collection for managing LiteLLM virtual keys in Red Hat Demo Platform (RHDP) lab environments.
Creates and deletes AI model access keys for lab users. Each lab gets a unique key named virtkey-{GUID} with access to specific AI models based on subscription tier.
- Prakhar Srivastava - Manager, Technical Marketing, Red Hat
- Ashok Jammula - Red Hat
- Tony Kay - LiteMaaS upstream project
- Ritesh Shah - Architecture and design guidance
ansible-galaxy collection install rhpds.litellm_virtual_keysansible-playbook playbook.yml \
-e ACTION=provision \
-e guid=user123 \
-e litellm_url=https://litellm-rhpds.apps.cluster.com \
-e litellm_master_key=sk-xxxxxansible-playbook playbook.yml \
-e ACTION=destroy \
-e guid=user123 \
-e litellm_url=https://litellm-rhpds.apps.cluster.com \
-e litellm_master_key=sk-xxxxxChoose what models and how long:
| Package | Models | Duration | Use Case |
|---|---|---|---|
ai-beginner |
Granite | 7 days | Intro workshops |
ai-developer |
Granite + Mistral | 30 days | Developer labs (default) |
ai-researcher |
Granite + Mistral + Llama | 90 days | Research projects |
lab-dev |
Granite + Mistral | 14 days | Development testing |
lab-prod |
Granite + Mistral | 90 days | Production labs |
When you create a key, users receive an email with:
LiteLLM API Endpoint: https://litellm-rhpds.apps.cluster.com/v1
LiteLLM Virtual Key: sk-abc123xyz...
Available Models: openai/granite-3-2-8b-instruct, openai/mistral-7b-instruct
Key Duration: 30d
These messages come from the agnosticd_user_info module and appear in:
- User provisioning emails
- RHDP web UI notifications
- Babylon catalog item details
The collection also stores structured data that automation can read:
litellm_api_endpoint: "https://litellm-rhpds.apps.cluster.com"
litellm_api_base_url: "https://litellm-rhpds.apps.cluster.com/v1"
litellm_virtual_key: "sk-abc123xyz..."
litellm_key_alias: "virtkey-user123"
litellm_available_models:
- "openai/granite-3-2-8b-instruct"
- "openai/mistral-7b-instruct"
litellm_key_duration: "30d"
litellm_subscription_package: "ai-developer"This data is accessible via:
- AgnosticD variables and facts
- RHDP API endpoints
- User info JSON exports
User info is enabled by default when running in AgnosticD context. The collection includes the agnosticd_user_info module, so it works out of the box.
To disable (for testing):
ocp4_workload_litellm_virtual_keys_enable_user_info_messages: false
ocp4_workload_litellm_virtual_keys_enable_user_info_data: false---
- name: Provision LiteLLM Key for Lab
hosts: localhost
gather_facts: false
vars:
ACTION: "provision"
guid: "{{ lookup('env', 'GUID') }}"
litellm_url: "https://litellm-rhpds.apps.cluster.com"
litellm_master_key: "{{ lookup('env', 'LITELLM_MASTER_KEY') }}"
# Optional: Choose subscription package
ocp4_workload_litellm_virtual_keys_subscription_package: "ai-developer"
tasks:
- name: Create virtual key
include_role:
name: rhpds.litellm_virtual_keys.ocp4_workload_litellm_virtual_keys
- name: Show key to user
debug:
msg:
- "Your AI API Key: {{ litellm_virtual_key }}"
- "API Endpoint: {{ litellm_api_endpoint }}/v1"
- "Models: {{ litellm_available_models | join(', ') }}"ACTION: Set toprovision(create key) ordestroy(delete key)guid: Lab environment identifier (e.g.,abc123)litellm_url: LiteLLM API URLlitellm_master_key: LiteLLM admin key
ocp4_workload_litellm_virtual_keys_subscription_package: Package name (default:ai-developer)ocp4_workload_litellm_virtual_keys_force_db_delete: Force database deletion if API fails (default:false)ocp4_workload_litellm_virtual_keys_namespace: Kubernetes namespace (default:rhpds)
cd tests
# Create a test key
ansible-playbook test_provision.yml \
-e litellm_url="https://litellm.example.com" \
-e litellm_master_key="sk-xxxxx"
# Delete the test key
ansible-playbook test_destroy.yml \
-e litellm_url="https://litellm.example.com" \
-e litellm_master_key="sk-xxxxx"See tests/README.md for detailed testing instructions.
All keys follow the pattern: virtkey-{GUID}
Example: If guid=abc123, the key alias is virtkey-abc123
- Create: Generate key with selected models and duration
- Use: Students access AI models via the key
- Expire: Key automatically expires after duration
- Delete: Manual cleanup when lab ends
Safe to run multiple times:
- Creating an existing key → skips, returns existing key
- Deleting a missing key → skips, no error
Enable database deletion workaround:
ocp4_workload_litellm_virtual_keys_force_db_delete: trueThis directly removes keys from PostgreSQL if the API fails.
Check that models are configured in LiteLLM admin UI under "Personal Models".
Verify master key:
oc get secret litellm-secret -n rhpds \
-o jsonpath='{.data.LITELLM_MASTER_KEY}' | base64 -dhttps://github.com/rhpds/rhpds.litellm_virtual_keys
MIT