dettonville.llm.hf_download module – Download files or repositories dynamically from Hugging Face Hub.

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.hf_download.

New in dettonville.llm 2.20.0

Synopsis

  • Downloads models, datasets, or specific files from Hugging Face Hub using the huggingface_hub library. Features dynamic filename resolution, etag/hash checking for updates, authentication tokens, revisions, subfolders, force-download controls, file permission adjustments, and idempotent local cache management.

Parameters

Parameter

Comments

attributes

aliases: attr

string

The attributes the resulting filesystem object should have.

To get supported flags look at the man page for chattr on the target system.

This string should contain the attributes in the same order as the one displayed by lsattr.

The = operator is assumed as default, otherwise + or - operators need to be included in the string.

filename

string

Name of the specific file to download. If omitted, the module can resolve filenames matching standard patterns or download all repo files.

force_download

boolean

Whether to force downloading files even if they already match remote checksums.

Choices:

  • false ← (default)

  • true

group

string

Name of the group that should own the filesystem object, as would be fed to chown.

When left unspecified, it uses the current group of the current user unless you are root, in which case it can preserve the previous ownership.

local_dir

string / required

Local folder where the file(s) should be downloaded.

any

Whether to use symlinks when downloading files locally.

Auto-detects based on system capabilities by default.

Option deprecated in recent huggingface_hub versions; kept for signature backward compatibility.

Default: "auto"

local_files_only

boolean

Whether to only inspect local files without checking HF Hub for remote updates.

Choices:

  • false ← (default)

  • true

mode

any

The permissions the resulting filesystem object should have.

For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must give Ansible enough information to parse them correctly. For consistent results, quote octal numbers (for example, '644' or '1777') so Ansible receives a string and can do its own conversion from string into number. Adding a leading zero (for example, 0755) works sometimes, but can fail in loops and some other circumstances.

Giving Ansible a number without following either of these rules will end up with a decimal number which will have unexpected results.

As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r).

If mode is not specified and the destination filesystem object does not exist, the default umask on the system will be used when setting the mode for the newly created filesystem object.

If mode is not specified and the destination filesystem object does exist, the mode of the existing filesystem object will be used.

Specifying mode is the best way to ensure filesystem objects are created with the correct permissions. See CVE-2020-1736 for further details.

owner

string

Name of the user that should own the filesystem object, as would be fed to chown.

When left unspecified, it uses the current user unless you are root, in which case it can preserve the previous ownership.

Specifying a numeric username will be assumed to be a user ID and not a username. Avoid numeric usernames to avoid this confusion.

quant_preference

string

Target quantization pattern (e.g., ‘Q4_K_M’, ‘NVFP4’) to automatically select a matching file if `filename` is omitted.

repo_id

string / required

The Hugging Face repository ID (e.g., ‘unsloth/Qwen3.8-27B-GGUF’).

repo_type

string

Type of repository (‘model’, ‘dataset’, ‘space’).

Choices:

  • "model" ← (default)

  • "dataset"

  • "space"

revision

string

An optional revision ID (branch name, tag, or commit hash).

selevel

string

The level part of the SELinux filesystem object context.

This is the MLS/MCS attribute, sometimes known as the range.

When set to _default, it will use the level portion of the policy if available.

serole

string

The role part of the SELinux filesystem object context.

When set to _default, it will use the role portion of the policy if available.

setype

string

The type part of the SELinux filesystem object context.

When set to _default, it will use the type portion of the policy if available.

seuser

string

The user part of the SELinux filesystem object context.

By default it uses the system policy, where applicable.

When set to _default, it will use the user portion of the policy if available.

subfolder

string

Subfolder inside the repository where the file is located.

token

string

Hugging Face API token for authenticating gated or private repos.

unsafe_writes

boolean

Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target filesystem object.

By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target filesystem objects, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted filesystem objects, which cannot be updated atomically from inside the container and can only be written in an unsafe manner.

This option allows Ansible to fall back to unsafe methods of updating filesystem objects when atomic operations fail (however, it doesn’t force Ansible to perform unsafe writes).

IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption.

Choices:

  • false ← (default)

  • true

Attributes

Attribute

Support

Description

check_mode

Support: full

Supports check mode to predict changes without downloading files.

diff_mode

Support: none

Does not support diff mode.

platform

Platform: posix

Target system must be POSIX-compliant.

safe_file_operations

Support: full

Uses Ansible’s atomic file creation and attributes handlers.

vault

Support: none

Does not directly decrypt vault-encrypted payload files.

Examples

- name: Ensure LLM models are present and up to date
  dettonville.llm.hf_download:
    repo_id: "unsloth/Qwen3.8-27B-NVFP4"
    quant_preference: "UD-Q4_K_M"
    local_dir: "/opt/llm/models"
    token: "{{ lookup('env', 'HF_TOKEN') }}"
    owner: "vllm"
    group: "vllm"
  register: model_download_results

- name: Download a GGUF model file
  dettonville.llm.hf_download:
    repo_id: "TheBloke/Llama-2-7B-Chat-GGUF"
    filename: "llama-2-7b-chat.Q4_K_M.gguf"
    local_dir: "/opt/llm/models"
    owner: "vllm"
    group: "vllm"

- name: Download a gated model file using authentication token
  dettonville.llm.hf_download:
    repo_id: "meta-llama/Meta-Llama-3-8B-Instruct"
    filename: "model.safetensors"
    local_dir: "/opt/llm/models/llama3"
    token: "{{ lookup('env', 'HF_TOKEN') }}"

- name: Download a file from a specific revision/branch
  dettonville.llm.hf_download:
    repo_id: "mistralai/Mistral-7B-v0.1"
    filename: "config.json"
    local_dir: "/opt/llm/models/mistral"
    revision: "refs/pr/1"

- name: Download a file located within a repository subfolder
  dettonville.llm.hf_download:
    repo_id: "unsloth/llama-3-8b-Instruct-bnb-4bit"
    filename: "tokenizer.json"
    local_dir: "/opt/llm/models/unsloth"
    subfolder: "tokenizers"

- name: Force re-download a file ignoring local cache
  dettonville.llm.hf_download:
    repo_id: "TheBloke/Llama-2-7B-Chat-GGUF"
    filename: "llama-2-7b-chat.Q4_K_M.gguf"
    local_dir: "/opt/llm/models"
    force_download: true

- name: Restrict downloads to local cache only
  dettonville.llm.hf_download:
    repo_id: "TheBloke/Llama-2-7B-Chat-GGUF"
    filename: "llama-2-7b-chat.Q4_K_M.gguf"
    local_dir: "/opt/llm/models"
    local_files_only: true

Return Values

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

Key

Description

changed

boolean

Whether any downloads or file updates took place.

Returned: always

downloaded_files

list / elements=string

List of files downloaded or verified.

Returned: success

resolved_filename

string

Primary resolved filename that was downloaded.

Returned: success

Authors

  • Lee Johnson (@lj020326)