diff --git a/ansible/inventory.yaml b/ansible/inventory.yaml index 86bb467..fabadc5 100644 --- a/ansible/inventory.yaml +++ b/ansible/inventory.yaml @@ -22,3 +22,4 @@ all: hosts: mac-mini: ansible_host: 192.168.7.96 + ansible_python_interpreter: /usr/bin/python3 diff --git a/ansible/playbooks/setup-ollama.yaml b/ansible/playbooks/setup-ollama.yaml new file mode 100644 index 0000000..e6d7a29 --- /dev/null +++ b/ansible/playbooks/setup-ollama.yaml @@ -0,0 +1,9 @@ +--- +# Run: ansible-playbook ansible/playbooks/setup-ollama.yaml -i ansible/inventory.yaml --ask-become-pass +# Description: Installs Ollama on the Mac Mini, configures it as a launchd daemon listening on all interfaces, and pulls the configured models. + +- name: Setup Ollama on Mac Mini + hosts: mac_mini + gather_facts: true + roles: + - ollama \ No newline at end of file diff --git a/ansible/roles/ollama/defaults/main.yaml b/ansible/roles/ollama/defaults/main.yaml new file mode 100644 index 0000000..a54a58c --- /dev/null +++ b/ansible/roles/ollama/defaults/main.yaml @@ -0,0 +1,9 @@ +--- +# Part of role: ollama +# Called by: ansible/playbooks/setup-ollama.yaml +# Description: Default variables for the ollama role. Add models to ollama_models to have them pulled automatically. + +ollama_host: "0.0.0.0" +ollama_port: 11434 +ollama_models: + - qwen3:4b \ No newline at end of file diff --git a/ansible/roles/ollama/handlers/main.yaml b/ansible/roles/ollama/handlers/main.yaml new file mode 100644 index 0000000..bca10ab --- /dev/null +++ b/ansible/roles/ollama/handlers/main.yaml @@ -0,0 +1,8 @@ +--- +# Part of role: ollama +# Called by: ansible/playbooks/setup-ollama.yaml +# Description: Handlers for the ollama role. Restarts the ollama launchd daemon when the plist changes. + +- name: restart ollama + become: true + command: launchctl kickstart -k system/com.ollama.ollama \ No newline at end of file diff --git a/ansible/roles/ollama/tasks/main.yaml b/ansible/roles/ollama/tasks/main.yaml new file mode 100644 index 0000000..c036839 --- /dev/null +++ b/ansible/roles/ollama/tasks/main.yaml @@ -0,0 +1,41 @@ +--- +# Part of role: ollama +# Called by: ansible/playbooks/setup-ollama.yaml +# Description: Installs Ollama via Homebrew, deploys the launchd plist so it starts on boot bound to all interfaces, and pulls configured models. + +- name: Install ollama via Homebrew + community.general.homebrew: + name: ollama + state: present + +- name: Deploy ollama launchd plist + template: + src: ollama.plist.j2 + dest: /Library/LaunchDaemons/com.ollama.ollama.plist + owner: root + group: wheel + mode: "0644" + become: true + notify: restart ollama + +- name: Load ollama launchd service + become: true + command: launchctl load -w /Library/LaunchDaemons/com.ollama.ollama.plist + args: + creates: /var/run/ollama.pid + ignore_errors: true + +- name: Wait for ollama to be ready + uri: + url: "http://localhost:{{ ollama_port }}" + status_code: 200 + register: result + until: result.status == 200 + retries: 10 + delay: 3 + +- name: Pull ollama models + command: /opt/homebrew/bin/ollama pull {{ item }} + loop: "{{ ollama_models }}" + environment: + OLLAMA_HOST: "http://localhost:{{ ollama_port }}" \ No newline at end of file diff --git a/ansible/roles/ollama/templates/ollama.plist.j2 b/ansible/roles/ollama/templates/ollama.plist.j2 new file mode 100644 index 0000000..3114bed --- /dev/null +++ b/ansible/roles/ollama/templates/ollama.plist.j2 @@ -0,0 +1,37 @@ + + + + + + + + Label + com.ollama.ollama + + ProgramArguments + + /opt/homebrew/bin/ollama + serve + + + EnvironmentVariables + + OLLAMA_HOST + {{ ollama_host }}:{{ ollama_port }} + HOME + /var/root + + + RunAtLoad + + + KeepAlive + + + StandardOutPath + /var/log/ollama.log + + StandardErrorPath + /var/log/ollama.error.log + + \ No newline at end of file diff --git a/manifests/core/ollama-external.yaml b/manifests/core/ollama-external.yaml new file mode 100644 index 0000000..99ae973 --- /dev/null +++ b/manifests/core/ollama-external.yaml @@ -0,0 +1,28 @@ +--- +# Apply: kubectl apply -f manifests/core/ollama-external.yaml +# Delete: kubectl delete -f manifests/core/ollama-external.yaml +# Description: Exposes the Mac Mini's Ollama instance to the K3s cluster via a headless Service + Endpoints pair. +# Allows any pod to reach Ollama at http://ollama.default.svc.cluster.local:11434 + +apiVersion: v1 +kind: Endpoints +metadata: + name: ollama + namespace: default +subsets: + - addresses: + - ip: 192.168.7.96 + ports: + - port: 11434 +--- +apiVersion: v1 +kind: Service +metadata: + name: ollama + namespace: default +spec: + ports: + - name: http + port: 11434 + targetPort: 11434 + clusterIP: None \ No newline at end of file