84 lines
2.9 KiB
YAML

---
# Part of role: ollama
# Called by: ansible/playbooks/setup-ollama.yaml
# 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:
src: ollama.plist.j2
dest: /Library/LaunchDaemons/com.ollama.ollama.plist
owner: root
group: wheel
mode: "0644"
become: true
notify: restart ollama
when: ansible_system == 'Darwin'
- 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
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 }}"
status_code: 200
register: result
until: result.status == 200
retries: 10
delay: 3
- name: Check installed ollama models
uri:
url: "http://localhost:{{ ollama_port }}/api/tags"
return_content: true
register: ollama_tags
- name: Pull ollama models
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:
OLLAMA_HOST: "http://localhost:{{ ollama_port }}"