feat: add configuration for GPU node setup and update Ollama role for cross-platform support

This commit is contained in:
Nik Afiq 2026-05-20 23:17:23 +09:00
parent d3069eb234
commit 0bf7f0f597
8 changed files with 101 additions and 9 deletions

View File

@ -0,0 +1,7 @@
# Host vars for: debian (k3s storage agent)
ansible_python_interpreter: /usr/bin/python3.11
k3s_node_labels:
node-role: storage
k3s_node_taints: []

View File

@ -0,0 +1,2 @@
# Host vars for: minisforum (k3s server)
ansible_python_interpreter: /usr/bin/python3.13

View File

@ -23,3 +23,10 @@ all:
mac-mini:
ansible_host: 192.168.7.96
ansible_python_interpreter: /usr/bin/python3
gpu_workstation:
hosts:
gpu-node:
ansible_host: 192.168.7.98
ansible_port: 430
ansible_python_interpreter: /usr/bin/python3.12

View File

@ -0,0 +1,12 @@
# Config for: gpu-node workstation full setup
# Applied by: ansible-playbook -i ansible/inventory.yaml ansible/playbooks/setup-gpu-node.yaml
- name: gpu-node setup
hosts: gpu_workstation
become: true
roles:
- role: common
- role: nvidia
- role: k3s-agent
- role: ollama
- role: glances

View File

@ -1,7 +1,8 @@
---
# Part of role: k3s-agent
# Called by: ansible/playbooks/join-debian-agent.yaml
# Description: Installs K3s in agent mode, joins the cluster, and labels the node as storage.
# ansible/playbooks/setup-gpu-node.yaml
# Description: Installs K3s in agent mode, joins the cluster, labels and taints the node.
- name: Download and install K3s agent
ansible.builtin.shell:
@ -20,11 +21,24 @@
enabled: true
become: true
- name: Label node as storage
- name: Apply node labels
ansible.builtin.shell:
cmd: >
k3s kubectl label node nik-debian
node-role=storage --overwrite
k3s kubectl label node {{ ansible_hostname }}
{{ item.key }}={{ item.value }} --overwrite
loop: "{{ k3s_node_labels | dict2items }}"
delegate_to: minisforum
become: true
changed_when: false
when: k3s_node_labels is defined and k3s_node_labels | length > 0
- name: Apply node taints
ansible.builtin.shell:
cmd: >
k3s kubectl taint node {{ ansible_hostname }}
{{ item }} --overwrite
loop: "{{ k3s_node_taints }}"
delegate_to: minisforum
become: true
changed_when: false
when: k3s_node_taints is defined and k3s_node_taints | length > 0

View File

@ -1,8 +1,17 @@
---
# 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.
# ansible/playbooks/setup-gpu-node.yaml
# Description: Handlers for the ollama role. Restarts ollama on config changes.
- name: restart ollama
become: true
command: launchctl kickstart -k system/com.ollama.ollama
when: ansible_system == 'Darwin'
- name: restart ollama linux
ansible.builtin.systemd:
name: ollama
state: restarted
daemon_reload: true
become: true
when: ansible_system == 'Linux'

View File

@ -1,12 +1,16 @@
---
# 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.
# ansible/playbooks/setup-gpu-node.yaml
# Description: Installs Ollama, configures it to bind to all interfaces, and pulls models.
# Supports macOS (Homebrew + launchd) and Linux (install script + systemd).
# ── macOS ──────────────────────────────────────────────────────────────────────
- name: Install ollama via Homebrew
community.general.homebrew:
name: ollama
state: present
when: ansible_system == 'Darwin'
- name: Deploy ollama launchd plist
template:
@ -17,6 +21,7 @@
mode: "0644"
become: true
notify: restart ollama
when: ansible_system == 'Darwin'
- name: Load ollama launchd service
become: true
@ -24,7 +29,36 @@
args:
creates: /var/run/ollama.pid
ignore_errors: true
when: ansible_system == 'Darwin'
# ── Linux ──────────────────────────────────────────────────────────────────────
- name: Install ollama via install script
ansible.builtin.shell:
cmd: curl -fsSL https://ollama.com/install.sh | sh
creates: /usr/local/bin/ollama
when: ansible_system == 'Linux'
- name: Deploy ollama systemd override
ansible.builtin.template:
src: ollama-override.conf.j2
dest: /etc/systemd/system/ollama.service.d/override.conf
owner: root
group: root
mode: "0644"
become: true
notify: restart ollama linux
when: ansible_system == 'Linux'
- name: Enable and start ollama service
ansible.builtin.systemd:
name: ollama
state: started
enabled: true
daemon_reload: true
become: true
when: ansible_system == 'Linux'
# ── shared ─────────────────────────────────────────────────────────────────────
- name: Wait for ollama to be ready
uri:
url: "http://localhost:{{ ollama_port }}"
@ -41,7 +75,9 @@
register: ollama_tags
- name: Pull ollama models
command: /opt/homebrew/bin/ollama pull {{ item }}
command: >
{{ '/opt/homebrew/bin/ollama' if ansible_system == 'Darwin' else '/usr/local/bin/ollama' }}
pull {{ item }}
loop: "{{ ollama_models }}"
when: item not in (ollama_tags.json.models | map(attribute='name') | list)
environment:

View File

@ -0,0 +1,5 @@
# Managed by Ansible — do not edit manually
[Service]
Environment="OLLAMA_HOST=0.0.0.0"
Environment="OLLAMA_PORT={{ ollama_port }}"
Environment="OLLAMA_MODELS={{ ollama_models_dir | default('/usr/share/ollama/.ollama/models') }}"