07_openwebui.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ---
  2. # playbooks/07_openwebui.yml
  3. # Deploy Open WebUI on ai_server
  4. - name: "Open WebUI | Deploy Open WebUI"
  5. hosts: ai_server
  6. become: true
  7. gather_facts: false
  8. tags:
  9. - openwebui
  10. vars:
  11. vault_token_file: "{{ playbook_dir }}/../vault/.vault-token"
  12. vault_url: "http://{{ ai_server_ip }}:{{ vault_port }}"
  13. openwebui_container_name: open-webui
  14. openwebui_data_dir: /mnt/ai_data/open-webui
  15. tasks:
  16. # ── Retrieve secrets from Vault ──────────────────────────────────
  17. - name: "Open WebUI | Retrieve Ollama API key from Vault"
  18. ansible.builtin.set_fact:
  19. ollama_api_key: "{{ lookup('community.hashi_vault.hashi_vault', vault_secret_prefix ~ '/ollama:api_key token=' ~ lookup('ansible.builtin.file', vault_token_file) ~ ' url=' ~ vault_url) }}"
  20. tags:
  21. - openwebui-secrets
  22. - name: "Open WebUI | Retrieve Keycloak client secret from Vault"
  23. ansible.builtin.set_fact:
  24. keycloak_client_secret: "{{ lookup('community.hashi_vault.hashi_vault', vault_secret_prefix ~ '/keycloak:client_secret token=' ~ lookup('ansible.builtin.file', vault_token_file) ~ ' url=' ~ vault_url) }}"
  25. tags:
  26. - openwebui-secrets
  27. - name: "Open WebUI | Retrieve Open WebUI secret key from Vault"
  28. ansible.builtin.set_fact:
  29. openwebui_secret_key: "{{ lookup('community.hashi_vault.hashi_vault', vault_secret_prefix ~ '/openwebui:secret_key token=' ~ lookup('ansible.builtin.file', vault_token_file) ~ ' url=' ~ vault_url) }}"
  30. tags:
  31. - openwebui-secrets
  32. - name: "Open WebUI | Retrieve OIDC URL from Vault"
  33. ansible.builtin.set_fact:
  34. keycloak_oidc_url: "{{ lookup('community.hashi_vault.hashi_vault', vault_secret_prefix ~ '/keycloak:oidc_url token=' ~ lookup('ansible.builtin.file', vault_token_file) ~ ' url=' ~ vault_url) }}"
  35. tags:
  36. - openwebui-secrets
  37. - name: "Open WebUI | Store Bedrock bearer token in Vault"
  38. ansible.builtin.uri:
  39. url: "{{ vault_url }}/v1/{{ vault_secret_prefix }}/bedrock"
  40. method: POST
  41. headers:
  42. X-Vault-Token: "{{ lookup('ansible.builtin.file', vault_token_file) }}"
  43. body_format: json
  44. body:
  45. data:
  46. bearer_token: "{{ bedrock_bearer_token }}"
  47. status_code: [200, 204]
  48. when: bedrock_bearer_token is defined and bedrock_bearer_token | length > 0
  49. tags:
  50. - openwebui-secrets
  51. - name: "Open WebUI | Retrieve Bedrock bearer token from Vault"
  52. block:
  53. - name: "Open WebUI | Fetch Bedrock bearer token"
  54. ansible.builtin.set_fact:
  55. _bedrock_token: "{{ lookup('community.hashi_vault.hashi_vault', vault_secret_prefix ~ '/bedrock:bearer_token token=' ~ lookup('ansible.builtin.file', vault_token_file) ~ ' url=' ~ vault_url) }}"
  56. rescue:
  57. - name: "Open WebUI | Bedrock not configured, skipping"
  58. ansible.builtin.set_fact:
  59. _bedrock_token: ""
  60. tags:
  61. - openwebui-secrets
  62. # ── Container deployment ─────────────────────────────────────────
  63. - name: "Open WebUI | Stop and remove existing container"
  64. community.docker.docker_container:
  65. name: "{{ openwebui_container_name }}"
  66. state: absent
  67. tags:
  68. - openwebui-deploy
  69. - name: "Open WebUI | Create data directory"
  70. ansible.builtin.file:
  71. path: "{{ openwebui_data_dir }}"
  72. state: directory
  73. mode: "0755"
  74. owner: root
  75. group: root
  76. tags:
  77. - openwebui-deploy
  78. - name: "Open WebUI | Build container environment"
  79. ansible.builtin.set_fact:
  80. _openwebui_env: >-
  81. {{
  82. {
  83. 'OLLAMA_BASE_URLS': 'http://host.docker.internal:11434;http://host.docker.internal:11435',
  84. 'OLLAMA_API_KEY': ollama_api_key,
  85. 'WEBUI_SECRET_KEY': openwebui_secret_key,
  86. 'WEBUI_AUTH': 'true',
  87. 'ENABLE_OAUTH_SIGNUP': 'true',
  88. 'OAUTH_PROVIDER_NAME': platform_name,
  89. 'OAUTH_CLIENT_ID': 'open-webui',
  90. 'OAUTH_CLIENT_SECRET': keycloak_client_secret,
  91. 'OPENID_PROVIDER_URL': keycloak_oidc_url ~ '/.well-known/openid-configuration',
  92. 'OAUTH_SCOPES': 'openid email profile',
  93. 'ENABLE_OAUTH_ROLE_MANAGEMENT': 'true',
  94. 'OAUTH_ROLES_CLAIM': 'realm_access.roles',
  95. 'OAUTH_ALLOWED_ROLES': 'ai-user,ai-admin',
  96. 'OAUTH_ADMIN_ROLES': 'ai-admin',
  97. 'ENABLE_RAG_WEB_SEARCH': 'false',
  98. 'RAG_EMBEDDING_ENGINE': 'ollama',
  99. 'RAG_EMBEDDING_MODEL': 'nomic-embed-text',
  100. 'RAG_OLLAMA_BASE_URL': 'http://host.docker.internal:11434',
  101. 'VECTOR_DB': 'qdrant',
  102. 'QDRANT_URI': 'http://host.docker.internal:6333',
  103. 'ENABLE_ADMIN_EXPORT': 'true',
  104. 'DEFAULT_MODELS': 'llama-family',
  105. 'WEBUI_NAME': platform_name,
  106. } | combine(
  107. {
  108. 'OPENAI_API_BASE_URL': 'https://bedrock-runtime.' ~ bedrock_aws_region ~ '.amazonaws.com/v1',
  109. 'OPENAI_API_KEY': _bedrock_token,
  110. } if _bedrock_token | default('') | length > 0 else {}
  111. )
  112. }}
  113. tags:
  114. - openwebui-deploy
  115. - name: "Open WebUI | Run Open WebUI container"
  116. community.docker.docker_container:
  117. name: "{{ openwebui_container_name }}"
  118. image: ghcr.io/open-webui/open-webui:main
  119. state: started
  120. restart_policy: unless-stopped
  121. ports:
  122. - "8080:8080"
  123. etc_hosts:
  124. host.docker.internal: host-gateway
  125. volumes:
  126. - "{{ openwebui_data_dir }}:/app/backend/data"
  127. env: "{{ _openwebui_env }}"
  128. tags:
  129. - openwebui-deploy
  130. - name: "Open WebUI | Wait for Open WebUI to be ready"
  131. ansible.builtin.uri:
  132. url: "http://localhost:8080"
  133. method: GET
  134. status_code: 200
  135. timeout: 10
  136. register: openwebui_health
  137. retries: 30
  138. delay: 10
  139. until: openwebui_health.status == 200
  140. tags:
  141. - openwebui-deploy
  142. - name: "Open WebUI | Display status"
  143. ansible.builtin.debug:
  144. msg: "Open WebUI is running at http://localhost:8080 (proxied via {{ openwebui_url }})"
  145. tags:
  146. - openwebui-deploy