integration_openai.ymlΒΆ

---
- name: πŸ” Resolve LiteLLM backend selection for integration_openai
  set_fact:
    nextcloud_openai_use_litellm: "{{ ('svc-ai-litellm' in group_names) and ('web-app-openwebui' not in group_names) }}"
  changed_when: false

- name: πŸ”‘ Bind integration_openai to the LiteLLM gateway
  when: nextcloud_openai_use_litellm | bool
  block:
    - 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 LiteLLM virtual key for integration_openai api_key
      set_fact:
        nextcloud_openai_litellm_api_key: "{{ lookup('config', 'web-app-nextcloud', 'secrets.credentials.litellm_api_key') }}"
      changed_when: false
      no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"

    - name: πŸ”§ Provision integration_openai api_key for the LiteLLM gateway backend
      shell: >- # nocheck: container-exec-resolver  NEXTCLOUD_LOCAL_CID resolved at delegate_to runtime; container_address would return a manager-only subshell
        container exec -u {{ NEXTCLOUD_DOCKER_USER }} -e NC_OPENAI_API_KEY {{ NEXTCLOUD_LOCAL_CID | quote }}
        sh -c 'exec "$1" config:app:set integration_openai api_key --value "$NC_OPENAI_API_KEY"'
        _ {{ NEXTCLOUD_INTERNAL_OCC_COMMAND | quote }}
      environment:
        NC_OPENAI_API_KEY: "{{ nextcloud_openai_litellm_api_key }}"
      when: IS_STACK_HOST | bool
      register: nextcloud_openai_set_api_key
      changed_when: nextcloud_openai_set_api_key.stdout is search(' set to ')
      no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"