dettonville.llm.ollama_api module – Manage Ollama models and query states via API

Note

This module is part of the dettonville.llm collection (version 2026.8.2).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install dettonville.llm.

To use it in a playbook, specify: dettonville.llm.ollama_api.

New in dettonville.llm 2.20.0

Synopsis

  • Manages Ollama models and checks service health using standard HTTP API endpoints.

  • Provides capabilities to list available models, check running models in VRAM (ps), pull (download), create custom models, remove, and sync models against a target Ollama endpoint.

  • Supports API key authentication via parameter or OLLAMA_API_KEY environment variable.

Parameters

Parameter

Comments

action

string

Action to perform.

Choices:

  • "health"

  • "version"

  • "list" ← (default)

  • "ps"

  • "pull"

  • "create"

  • "delete"

  • "sync"

api_auth_type

string

Type of HTTP authentication header to use.

Choices:

  • "bearer" ← (default)

  • "basic"

api_key

string

Optional API token/key for authentication.

API key or user:password basic auth credential for the Ollama endpoint.

Can also be supplied via OLLAMA_API_KEY environment variable.

model_file_path

string

Path to local Modelfile content for custom model creation.

model_list

aliases: models

list / elements=string

List of model name strings to process in batch or sync against.

model_name

aliases: model

string

Single model name string to process or target for custom creation.

url

aliases: endpoint

string / required

Base URL of the Ollama API service.

use_system_certs

boolean

Whether to use the truststore library to hook Python’s ssl module into the native system certificate store.

Choices:

  • false

  • true ← (default)

validate_certs

boolean

Whether to validate SSL certificates for HTTPS requests.

Choices:

  • false

  • true ← (default)

Examples

- name: Check health of Ollama endpoint
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "health"

- name: Get Ollama version
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "version"

- name: List models on Ollama endpoint
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "list"

- name: Check running models loaded in VRAM
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "ps"

- name: Pull a model with explicit API key authentication
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "pull"
    model_name: "qwen2.5-coder:7b"
    api_key: "{{ lookup('env', 'OLLAMA_API_KEY') }}"
    api_auth_type: "bearer"

- name: Create a custom model from a local model file
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "create"
    model_name: "my-custom-model:latest"
    model_file_path: "/path/to/Modelfile"

- name: Remove an obsolete model using basic authentication
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "delete"
    model: "llama3.1:8b"
    api_key: "admin:secretpassword"
    api_auth_type: "basic"

- name: Pull a model using basic base64 encoded authentication
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "pull"
    model_name: "qwen2.5-coder:7b"
    api_key: "e1NTSEF9cGFzc3dvcmQ="   # explicit base64
    api_auth_type: "basic"

- name: Sync models on Ollama endpoint to match specified list exactly
  dettonville.llm.ollama_api:
    url: "https://ollama.example.com"
    action: "sync"
    model_list:
      - "qwen2.5-coder:7b"
      - "llama3.1:8b"

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

base_url

string

The target endpoint URL used.

Returned: always

changed

boolean

Whether any modification or state change occurred.

Returned: always

result

any

The JSON response dictionary or message returned from the Ollama API or action.

Returned: always

Authors

  • Lee Johnson (@lj020326)