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 |
|---|---|
The attributes the resulting filesystem object should have. To get supported flags look at the man page for This string should contain the attributes in the same order as the one displayed by The |
|
Name of the specific file to download. If omitted, the module can resolve filenames matching standard patterns or download all repo files. |
|
Whether to force downloading files even if they already match remote checksums. Choices:
|
|
Name of the group that should own the filesystem object, as would be fed to 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 folder where the file(s) should be downloaded. |
|
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: |
|
Whether to only inspect local files without checking HF Hub for remote updates. Choices:
|
|
The permissions the resulting filesystem object should have. For those used to 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, If If Specifying |
|
Name of the user that should own the filesystem object, as would be fed to 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. |
|
Target quantization pattern (e.g., ‘Q4_K_M’, ‘NVFP4’) to automatically select a matching file if `filename` is omitted. |
|
The Hugging Face repository ID (e.g., ‘unsloth/Qwen3.8-27B-GGUF’). |
|
Type of repository (‘model’, ‘dataset’, ‘space’). Choices:
|
|
An optional revision ID (branch name, tag, or commit hash). |
|
The level part of the SELinux filesystem object context. This is the MLS/MCS attribute, sometimes known as the When set to |
|
The role part of the SELinux filesystem object context. When set to |
|
The type part of the SELinux filesystem object context. When set to |
|
The user part of the SELinux filesystem object context. By default it uses the When set to |
|
Subfolder inside the repository where the file is located. |
|
Hugging Face API token for authenticating gated or private repos. |
|
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:
|
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full |
Supports check mode to predict changes without downloading files. |
|
Support: none |
Does not support diff mode. |
|
Platform: posix |
Target system must be POSIX-compliant. |
|
Support: full |
Uses Ansible’s atomic file creation and attributes handlers. |
|
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 |
|---|---|
Whether any downloads or file updates took place. Returned: always |
|
List of files downloaded or verified. Returned: success |
|
Primary resolved filename that was downloaded. Returned: success |