07_openwebui.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. # ── Container deployment ─────────────────────────────────────────
  38. - name: "Open WebUI | Stop and remove existing container"
  39. community.docker.docker_container:
  40. name: "{{ openwebui_container_name }}"
  41. state: absent
  42. tags:
  43. - openwebui-deploy
  44. - name: "Open WebUI | Create data directory"
  45. ansible.builtin.file:
  46. path: "{{ openwebui_data_dir }}"
  47. state: directory
  48. mode: "0755"
  49. owner: root
  50. group: root
  51. tags:
  52. - openwebui-deploy
  53. - name: "Open WebUI | Run Open WebUI container"
  54. community.docker.docker_container:
  55. name: "{{ openwebui_container_name }}"
  56. image: ghcr.io/open-webui/open-webui:main
  57. state: started
  58. restart_policy: unless-stopped
  59. ports:
  60. - "8080:8080"
  61. etc_hosts:
  62. host.docker.internal: host-gateway
  63. volumes:
  64. - "{{ openwebui_data_dir }}:/app/backend/data"
  65. env:
  66. OLLAMA_BASE_URL: "http://host.docker.internal:11434"
  67. OLLAMA_API_KEY: "{{ ollama_api_key }}"
  68. WEBUI_SECRET_KEY: "{{ openwebui_secret_key }}"
  69. WEBUI_AUTH: "true"
  70. ENABLE_OAUTH_SIGNUP: "true"
  71. OAUTH_PROVIDER_NAME: "{{ platform_name }}"
  72. OAUTH_CLIENT_ID: "open-webui"
  73. OAUTH_CLIENT_SECRET: "{{ keycloak_client_secret }}"
  74. OPENID_PROVIDER_URL: "{{ keycloak_oidc_url }}/.well-known/openid-configuration"
  75. OAUTH_SCOPES: "openid email profile"
  76. ENABLE_OAUTH_ROLE_MANAGEMENT: "true"
  77. OAUTH_ROLES_CLAIM: "realm_access.roles"
  78. OAUTH_ALLOWED_ROLES: "ai-user,ai-admin"
  79. OAUTH_ADMIN_ROLES: "ai-admin"
  80. ENABLE_RAG_WEB_SEARCH: "false"
  81. RAG_EMBEDDING_ENGINE: "ollama"
  82. RAG_EMBEDDING_MODEL: "nomic-embed-text"
  83. RAG_OLLAMA_BASE_URL: "http://host.docker.internal:11434"
  84. VECTOR_DB: "qdrant"
  85. QDRANT_URI: "http://host.docker.internal:6333"
  86. ENABLE_ADMIN_EXPORT: "true"
  87. DEFAULT_MODELS: "llama-family"
  88. WEBUI_NAME: "{{ platform_name }}"
  89. tags:
  90. - openwebui-deploy
  91. - name: "Open WebUI | Wait for Open WebUI to be ready"
  92. ansible.builtin.uri:
  93. url: "http://localhost:8080"
  94. method: GET
  95. status_code: 200
  96. timeout: 10
  97. register: openwebui_health
  98. retries: 30
  99. delay: 10
  100. until: openwebui_health.status == 200
  101. tags:
  102. - openwebui-deploy
  103. - name: "Open WebUI | Display status"
  104. ansible.builtin.debug:
  105. msg: "Open WebUI is running at http://localhost:8080 (proxied via {{ openwebui_url }})"
  106. tags:
  107. - openwebui-deploy