feat: add Ollama role with installation, configuration, and service exposure for K3s cluster
This commit is contained in:
parent
2bccbc14ef
commit
7d2fde96ae
@ -22,3 +22,4 @@ all:
|
||||
hosts:
|
||||
mac-mini:
|
||||
ansible_host: 192.168.7.96
|
||||
ansible_python_interpreter: /usr/bin/python3
|
||||
|
||||
9
ansible/playbooks/setup-ollama.yaml
Normal file
9
ansible/playbooks/setup-ollama.yaml
Normal file
@ -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
|
||||
9
ansible/roles/ollama/defaults/main.yaml
Normal file
9
ansible/roles/ollama/defaults/main.yaml
Normal file
@ -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
|
||||
8
ansible/roles/ollama/handlers/main.yaml
Normal file
8
ansible/roles/ollama/handlers/main.yaml
Normal file
@ -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
|
||||
41
ansible/roles/ollama/tasks/main.yaml
Normal file
41
ansible/roles/ollama/tasks/main.yaml
Normal file
@ -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 }}"
|
||||
37
ansible/roles/ollama/templates/ollama.plist.j2
Normal file
37
ansible/roles/ollama/templates/ollama.plist.j2
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Part of role: ollama -->
|
||||
<!-- Called by: ansible/roles/ollama/tasks/main.yaml -->
|
||||
<!-- Description: launchd daemon plist for Ollama on macOS. Binds to all interfaces so the K3s cluster can reach it via manifests/core/ollama-external.yaml. -->
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.ollama.ollama</string>
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/opt/homebrew/bin/ollama</string>
|
||||
<string>serve</string>
|
||||
</array>
|
||||
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>OLLAMA_HOST</key>
|
||||
<string>{{ ollama_host }}:{{ ollama_port }}</string>
|
||||
<key>HOME</key>
|
||||
<string>/var/root</string>
|
||||
</dict>
|
||||
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
|
||||
<key>StandardOutPath</key>
|
||||
<string>/var/log/ollama.log</string>
|
||||
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/var/log/ollama.error.log</string>
|
||||
</dict>
|
||||
</plist>
|
||||
28
manifests/core/ollama-external.yaml
Normal file
28
manifests/core/ollama-external.yaml
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user