267 lines
8.2 KiB
YAML
267 lines
8.2 KiB
YAML
---
|
|
- name: Verify open_webui role declarations
|
|
ansible.builtin.assert:
|
|
that:
|
|
- open_webui_image_ref is match('^ghcr.io/open-webui/open-webui@sha256:[0-9a-f]{64}$')
|
|
- open_webui_network_name == 'gnai-production-llama'
|
|
fail_msg: "open_webui must use the pinned digest and the Production network"
|
|
|
|
- name: Check whether the pinned OpenWebUI image is in the workload store
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/podman
|
|
- image
|
|
- exists
|
|
- "{{ open_webui_image_ref }}"
|
|
chdir: "{{ open_webui_home }}"
|
|
changed_when: false
|
|
failed_when: open_webui_image_present.rc not in [0, 1]
|
|
check_mode: false
|
|
register: open_webui_image_present
|
|
|
|
- name: Pull the pinned OpenWebUI image into the workload store
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/podman
|
|
- pull
|
|
- "{{ open_webui_image_ref }}"
|
|
chdir: "{{ open_webui_home }}"
|
|
when:
|
|
- not ansible_check_mode
|
|
- open_webui_image_present.rc != 0
|
|
|
|
- name: Ensure the OpenWebUI data directory exists
|
|
ansible.builtin.file:
|
|
path: "{{ open_webui_data_dir }}"
|
|
state: directory
|
|
owner: "{{ open_webui_user }}"
|
|
group: "{{ open_webui_user }}"
|
|
mode: "0750"
|
|
|
|
- name: Check whether the WebUI secret key already exists
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/podman
|
|
- secret
|
|
- exists
|
|
- "{{ open_webui_webui_secret_key_secret }}"
|
|
chdir: "{{ open_webui_home }}"
|
|
register: open_webui_secret_exists
|
|
changed_when: false
|
|
failed_when: open_webui_secret_exists.rc not in [0, 1]
|
|
check_mode: false
|
|
|
|
- name: Create the WebUI secret key (random, on the host only)
|
|
# Piped via stdin: a root-created temp file would not be readable by the
|
|
# workload user (umask), so the secret never touches the filesystem.
|
|
ansible.builtin.shell: |
|
|
set -euo pipefail
|
|
head -c 48 /dev/urandom | base64 \
|
|
| /usr/sbin/runuser --user {{ open_webui_user }} -- /usr/bin/env \
|
|
HOME={{ open_webui_home }} XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }} \
|
|
/usr/bin/podman secret create {{ open_webui_webui_secret_key_secret }} -
|
|
# runuser keeps the caller's cwd; the workload user cannot traverse
|
|
# /home/ansible-deploy, so run from the workload home.
|
|
args:
|
|
executable: /bin/bash
|
|
chdir: "{{ open_webui_home }}"
|
|
when: open_webui_secret_exists.rc == 1
|
|
no_log: true
|
|
|
|
- name: Check whether the engine API key secret already exists
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/podman
|
|
- secret
|
|
- exists
|
|
- "{{ open_webui_engine_api_key_secret }}"
|
|
chdir: "{{ open_webui_home }}"
|
|
register: open_webui_engine_secret_exists
|
|
changed_when: false
|
|
failed_when: open_webui_engine_secret_exists.rc not in [0, 1]
|
|
check_mode: false
|
|
|
|
- name: Create the engine API key secret (placeholder, llama.cpp has no auth)
|
|
ansible.builtin.shell: |
|
|
set -euo pipefail
|
|
printf 'local-noauth-%s' "$(head -c 16 /dev/urandom | base64)" \
|
|
| /usr/sbin/runuser --user {{ open_webui_user }} -- /usr/bin/env \
|
|
HOME={{ open_webui_home }} XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }} \
|
|
/usr/bin/podman secret create {{ open_webui_engine_api_key_secret }} -
|
|
args:
|
|
executable: /bin/bash
|
|
chdir: "{{ open_webui_home }}"
|
|
when: open_webui_engine_secret_exists.rc == 1
|
|
no_log: true
|
|
|
|
- name: Check whether the OIDC client secret exists (required when OIDC is enabled)
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/podman
|
|
- secret
|
|
- exists
|
|
- "{{ open_webui_oidc_client_secret_secret }}"
|
|
chdir: "{{ open_webui_home }}"
|
|
changed_when: false
|
|
failed_when: false
|
|
check_mode: false
|
|
register: open_webui_oidc_secret_exists
|
|
|
|
- name: Note when OIDC is enabled with a public (PKCE) client and no secret
|
|
ansible.builtin.debug:
|
|
msg: >-
|
|
OIDC enabled; Podman secret {{ open_webui_oidc_client_secret_secret }}
|
|
absent — fine for a public client with PKCE. For a confidential client,
|
|
create the secret from the Keycloak client secret (never in git).
|
|
when:
|
|
- open_webui_oidc_enabled | bool
|
|
- open_webui_oidc_secret_exists.rc != 0
|
|
|
|
- name: Render the egress network quadlet
|
|
ansible.builtin.template:
|
|
src: egress.network.j2
|
|
dest: "{{ open_webui_quadlet_dir }}/{{ open_webui_egress_network_name }}.network"
|
|
owner: root
|
|
group: "{{ open_webui_user }}"
|
|
mode: "0640"
|
|
notify:
|
|
- Reload workload user manager
|
|
- Restart OpenWebUI unit
|
|
|
|
- name: Render the OpenWebUI quadlet
|
|
ansible.builtin.template:
|
|
src: open-webui.container.j2
|
|
dest: "{{ open_webui_quadlet_dir }}/{{ open_webui_unit_prefix }}.container"
|
|
owner: root
|
|
group: "{{ open_webui_user }}"
|
|
mode: "0640"
|
|
notify:
|
|
- Reload workload user manager
|
|
- Restart OpenWebUI unit
|
|
|
|
- name: Ensure the workload user manager knows the rendered unit
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/systemctl
|
|
- --user
|
|
- daemon-reload
|
|
chdir: "{{ open_webui_home }}"
|
|
changed_when: false
|
|
when: not ansible_check_mode
|
|
|
|
- name: Read the current state of the OpenWebUI unit
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/systemctl
|
|
- --user
|
|
- is-active
|
|
- "{{ open_webui_unit_prefix }}.service"
|
|
chdir: "{{ open_webui_home }}"
|
|
changed_when: false
|
|
failed_when: open_webui_unit_state.rc not in [0, 3]
|
|
check_mode: false
|
|
register: open_webui_unit_state
|
|
|
|
- name: Start the OpenWebUI unit
|
|
# Quadlet-generated units are transient and cannot be `enable`d directly;
|
|
# the [Install] section of the quadlet handles boot enablement, here we
|
|
# only start (same pattern as the inference_engine role).
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/systemctl
|
|
- --user
|
|
- start
|
|
- "{{ open_webui_unit_prefix }}.service"
|
|
chdir: "{{ open_webui_home }}"
|
|
when:
|
|
- not ansible_check_mode
|
|
- open_webui_unit_state.rc != 0
|
|
|
|
- name: Wait for the OpenWebUI health endpoint
|
|
ansible.builtin.uri:
|
|
url: "http://{{ open_webui_host_addr }}:{{ open_webui_host_port }}/health"
|
|
status_code: 200
|
|
timeout: 10
|
|
register: open_webui_health
|
|
retries: 30
|
|
delay: 5
|
|
until: open_webui_health.status == 200
|
|
when: not ansible_check_mode
|
|
|
|
- name: Verify the engine model list is reachable through OpenWebUI's network
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/sbin/runuser
|
|
- --user
|
|
- "{{ open_webui_user }}"
|
|
- --
|
|
- /usr/bin/env
|
|
- "HOME={{ open_webui_home }}"
|
|
- "XDG_RUNTIME_DIR=/run/user/{{ open_webui_uid }}"
|
|
- /usr/bin/podman
|
|
- exec
|
|
- "{{ open_webui_unit_prefix }}"
|
|
- /bin/sh
|
|
- -c
|
|
- "curl -fsS --max-time 10 {{ open_webui_engine_base_url }}/models | grep -q swift"
|
|
chdir: "{{ open_webui_home }}"
|
|
register: open_webui_models
|
|
changed_when: false
|
|
when: not ansible_check_mode
|