Reproducible Collection Resolution: Pinning Collections and Verifying What Installed
requirements.yml full of version ranges is not a lockfile, and an ansible-core pin
says nothing about which collections you will get. This guide builds and installs a tiny local collection,
demo.audit 1.0.0, so you can see exact resolution happen offline, then covers the limits of pinning
direct and transitive dependencies, the current configuration keys for collection paths, and what
ansible-galaxy collection verify does and does not prove.
Version scope and prerequisites
Written against ansible-core 2.22.0, released 2026-11-02, which requires a controller Python of
3.13 to 3.15. The configuration key names below were read from the configuration definitions shipped in that
release. Once the virtual environment exists, the demonstration is offline and local: it builds a collection
from source, installs the tarball, and runs one assertion. Nothing is fetched from galaxy.ansible.com, so the
result does not depend on an external collection's release history. The one step that does need the network is
the pip install below, unless you already have the ansible-core wheel cached or
mirrored.
Run this in your own virtual environment, not in the playground on this site, which pins an older ansible-core and does not install collections.
Common setup
mkdir -p ~/tma-collections && cd ~/tma-collections
python3.13 -m venv .venv
.venv/bin/python -m pip install 'ansible-core==2.22.0'
.venv/bin/ansible --version
Two pins, two different problems
Reproducibility in Ansible needs two independent decisions, and conflating them is the most common cause of a "but it worked last week" report.
The ansible-core pin fixes the engine: the templating rules, the module interface, the
configuration defaults, and the supported Python versions. It is a Python package pin and belongs in your
requirements.txt or equivalent, as ansible-core==2.22.0. Pinning the
ansible package instead fixes the bundled collection release set — core plus a curated set
of collections at the versions that release shipped — which is a different and much larger decision, and one that
upgrades collections whenever you bump the bundle. What it does not do is pin the engine exactly: the
bundle declares core as a compatible range, not a single version. The published metadata for
ansible 15.0.0 lists one dependency, ansible-core~=2.22.0, so any 2.22 patch release
satisfies it and two installs of the same bundle version can resolve different cores. If you want the engine
fixed as well, add an explicit, compatible ansible-core== constraint alongside the bundle pin. Even
then the pin covers one package: ansible-core has its own Python dependencies, and those have
dependencies in turn, so a fully reproducible controller environment means constraining the whole Python graph —
a pip freeze output, a constraints file, or a lock file from whichever Python tool you use.
The collection pins fix the content: the modules, filters and roles your playbooks call. These
live in requirements.yml and are installed with ansible-galaxy. Upstream is explicit
that a collection installed manually this way is not upgraded when you upgrade ansible or
ansible-core — the two sets of pins move independently, and only together do they describe your
runtime.
Range identifiers, and why ranges are not pins
ansible-galaxy accepts version range identifiers on the command line and in
requirements.yml: * (the most recent, and the default), ==,
!=, >=, >, <= and <. Several can be
combined with a comma. Quote them so the shell does not interpret the operators:
.venv/bin/ansible-galaxy collection install 'my_namespace.my_collection:==1.0.0'
.venv/bin/ansible-galaxy collection install 'my_namespace.my_collection:>=1.0.0,<2.0.0'
The key sentence from the upstream snippet is that Ansible always installs the most recent version that
satisfies your identifiers. A range therefore resolves differently on different days. Only == names
one version. Two further details: a collection can only be installed once at a time, so there is no way to hold
two versions of the same collection in one path; and pre-release versions are ignored unless you require one
explicitly with ==.
requirements.yml is not a lockfile.
Even with every direct dependency pinned to ==, the file records your intent, not the
resolved graph. Transitive dependencies — the collections your collections declare in their own
galaxy.yml — are resolved at install time against whatever the server offers, and the resolution
is not written back anywhere for you. You can constrain them: adding a transitive collection as its own
top-level entry with == pins that one too, and the resolver has to satisfy both your constraint and
the dependency declaration. What you do not get is the automatic, complete record a real lockfile gives you, so
doing this properly means enumerating every dependency in the graph yourself and keeping the list current. The
alternative, and usually the cheaper one, is to make the artefact the unit you keep: build or download the
tarballs once, retain all of them, and install from those. That is what the demonstration below does.
Where collections are found: the current keys
As shipped in 2.22.0, the setting that lists collection roots is defined once and exposed under three names:
- Internal constant:
COLLECTIONS_PATHS— plural. This is the name used inside ansible-core and in documentation cross-references, which is why you will see it in prose. - ansible.cfg key:
collections_pathin the[defaults]section — singular. This is what you write in a config file. - Environment variable:
ANSIBLE_COLLECTIONS_PATH— singular.
Despite the singular names, the value is a colon-separated list of roots, defaulting to
~/.ansible/collections:/usr/share/ansible/collections. Collections must live in nested
subdirectories under each root, not directly in it: a root of ./collections holds
./collections/ansible_collections/my_namespace/my_collection. The
ansible-galaxy collection install -p option appends ansible_collections for you unless
the parent directory is already called that.
Two more roots matter and are easy to forget. A collections/ansible_collections/ directory
adjacent to the playbook is searched regardless of what collections_path says — a feature,
since upstream recommends it so a project can be self-contained, version its collections alongside its
playbooks, and stay isolated from global installs. And COLLECTIONS_SCAN_SYS_PATH, which defaults to
true, makes ansible-core scan sys.path for installed
ansible_collections packages as well. Together these mean clearing
ANSIBLE_COLLECTIONS_PATH is not enough to prove a clean environment: you also need a
directory with no adjacent collections/ and
ANSIBLE_COLLECTIONS_SCAN_SYS_PATH=false. The negative case below does all three.
The demonstration: build, install and verify a local collection
demo.audit exists only to be pinned. It ships one filter plugin, so the assertion that calls it is
unambiguous proof that the right collection resolved from the right path. Run the steps in the order below: the
project configuration has to exist first, because ansible-galaxy collection list and
ansible-doc read collections_path from it, and without that they would report on your
home directory instead of the project.
1. Configure the project
Both files go in ~/tma-collections, next to the .venv you created above.
[defaults]
interpreter_python = auto_silent
collections_path = ./collections
[local]
localhost ansible_connection=local
collections_path = ./collections is relative to the config file, so every command in this section
resolves against the project rather than ~/.ansible/collections. Run the rest of the commands from
~/tma-collections so that ansible.cfg is picked up.
2. Scaffold the collection
cd ~/tma-collections
.venv/bin/ansible-galaxy collection init demo.audit --init-path ./src
Expected result: - Collection demo.audit was created successfully, and a tree under
./src/demo/audit/. The generated galaxy.yml is a heavily commented skeleton; replace it
with the minimal version below so the metadata that matters is visible.
---
namespace: demo
name: audit
version: 1.0.0
readme: README.md
authors:
- Example Author <author@example.com>
description: Local demonstration collection with one filter plugin.
license:
- MIT
tags:
- demo
dependencies: {}
version: 1.0.0 is the number the build writes into the artefact name and into
MANIFEST.json; it is what every later pin refers to. dependencies: {} is the
declaration that this collection pulls nothing else in — the key that, when non-empty, produces the transitive
resolution discussed below.
Add a runtime file so ansible-core knows which engine versions the collection claims to support:
---
requires_ansible: ">=2.22.0"
Without this file, installing prints
[WARNING]: demo.audit:1.0.0 does not have requires_ansible metadata. Real collections should declare
it: when a collection is loaded under an engine it does not claim to support, the
collections_on_ansible_version_mismatch setting decides whether you get a warning (the default) or
an error.
3. Add the filter plugin
from __future__ import annotations
DOCUMENTATION = r"""
name: audit_label
short_description: Build a stable audit label from a host name
description:
- Returns the lower-cased host name with a prefix, so audit records sort predictably.
options:
_input:
description: The host name to label.
type: str
required: true
prefix:
description: Label prefix.
type: str
default: audit
author:
- Example Author (@example)
"""
EXAMPLES = r"""
- name: Label a host
ansible.builtin.debug:
msg: "{{ 'Web-01' | demo.audit.audit_label }}"
"""
RETURN = r"""
_value:
description: The prefixed, lower-cased label.
type: str
"""
def audit_label(value, prefix="audit"):
if not isinstance(value, str):
raise TypeError(f"audit_label requires a string, got {type(value).__name__}")
return f"{prefix}:{value.strip().lower()}"
class FilterModule(object):
def filters(self):
return {"audit_label": audit_label}
The DOCUMENTATION, EXAMPLES and RETURN blocks are not decoration — they
are what ansible-doc reads, and they give you a way to confirm which copy of the plugin resolved.
4. Build the artefact
.venv/bin/ansible-galaxy collection build src/demo/audit --output-path ./dist
ls -l dist
Expected result: Created collection for demo.audit at …/dist/demo-audit-1.0.0.tar.gz, and one
tarball named after the namespace, name and version. That file is the unit of reproducibility. Keeping it in an
artefact store rather than the playbook repository only gives you identical bytes if the store is itself
immutable and content-addressed or checksummed; a mutable path that anyone can overwrite reintroduces exactly
the problem you were trying to remove, so record the artefact's checksum alongside the pin.
5. Pin it in requirements.yml and install
---
collections:
- name: ./dist/demo-audit-1.0.0.tar.gz
type: file
.venv/bin/ansible-galaxy collection install -r requirements.yml -p ./collections
Expected result:
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Installing 'demo.audit:1.0.0' to
'/home/you/tma-collections/collections/ansible_collections/demo/audit'
demo.audit:1.0.0 was installed successfully
The type key accepts file, galaxy, git, url,
dir and subdirs; omit it and the name determines the source. Two of these
deserve a warning. type: dir installs from a source directory and ignores any version range, so it
gives you whatever is on disk — convenient while developing, useless as a pin. type: git accepts a
branch in the version key, which is also not a pin. A tag is better but still not immutable —
tags can be moved or recreated — so use a full commit ID when you need the same content twice.
6. Verify what resolved
.venv/bin/ansible-galaxy collection list
.venv/bin/ansible-doc -t filter demo.audit.audit_label
.venv/bin/ansible-galaxy collection verify demo.audit --offline -p ./collections
Expected results, in order:
# /home/you/tma-collections/collections/ansible_collections
Collection Version
---------- -------
demo.audit 1.0.0
> FILTER demo.audit.audit_label (…/collections/ansible_collections/demo/audit/plugins/filter/audit_label.py)
Returns the lower-cased host name with a prefix, so audit records sort predictably.
…
Verifying 'demo.audit:1.0.0'.
Installed collection found at '…/collections/ansible_collections/demo/audit'
MANIFEST.json hash: cde9dd29…
Successfully verified that checksums for 'demo.audit:1.0.0' are internally
consistent with its manifest.
collection list prints the resolved version and the root it came from, which is the piece
people skip. ansible-doc prints the absolute path of the file that resolved, which settles any
argument about which copy is in use.
collection verify --offline checks the installed files against the checksums recorded in the
collection's own MANIFEST.json, so what it establishes is that the installed tree is
internally consistent with the manifest that is there now — which is exactly the wording the command
prints. That is weaker than "nothing has been edited since installation": the manifest is an ordinary file in
the same tree, so anyone who can rewrite a plugin can rewrite the manifest to match, and anyone who can swap the
tarball swaps the manifest with it. It therefore says nothing at all about where the artefact came from.
Upstream's online form of the command is a different check — without --offline it compares the
installed collection against the copy on a configured Galaxy server, which is only possible for collections that
exist there. Provenance needs signatures: a distribution server
that provides detached GPG signatures, a configured keyring, and
GALAXY_REQUIRED_VALID_SIGNATURE_COUNT set to the number you require (prefix it with +
to fail when no valid signature is found). Upstream notes that user-provided signatures are not used to
verify collections installed from git repositories, source directories, or tarball paths — which includes the
local install above.
To see what tampering looks like, append a comment to the installed plugin and verify again. Expected result: the modified file is named, so the check genuinely detects a change.
echo '# tampered' >> collections/ansible_collections/demo/audit/plugins/filter/audit_label.py
.venv/bin/ansible-galaxy collection verify demo.audit --offline -p ./collections
Collection demo.audit contains modified content in the following files:
plugins/filter/audit_label.py
Reinstalling over the same version needs --force, because the version already present satisfies
the requirement:
.venv/bin/ansible-galaxy collection install -r requirements.yml -p ./collections --force
.venv/bin/ansible-galaxy collection verify demo.audit --offline -p ./collections
Expected result: the install reports demo.audit:1.0.0 was installed successfully and
verify returns to the "internally consistent" message with exit status 0. One footnote on reading
that output: after a play has run against the collection, the run above also listed
plugins/filter/__pycache__ as modified content, because Python wrote bytecode into the installed
tree. Whether that appears depends on whether anything has imported the plugin yet, so verify a fresh install if
you want an unambiguous result.
7. Prove the pin with a playbook
ansible.cfg and hosts.ini are already in place from step 1, so this is the last file
to add:
---
- name: Prove the pinned collection is the one that resolved
hosts: local
gather_facts: false
tasks:
- name: The filter from demo.audit 1.0.0 is callable by its full name
ansible.builtin.assert:
that:
- "'Web-01' | demo.audit.audit_label == 'audit:web-01'"
- "'Web-01' | demo.audit.audit_label(prefix='scan') == 'scan:web-01'"
success_msg: demo.audit resolved from the project collections path.
.venv/bin/ansible-playbook -i hosts.ini play.yml --syntax-check
.venv/bin/ansible-playbook -i hosts.ini play.yml
Expected result: one task, ok, with
"msg": "demo.audit resolved from the project collections path." and a recap of
ok=1 changed=0 unreachable=0 failed=0. Note that the assertions use the fully qualified name
demo.audit.audit_label rather than the short name. A fully qualified name removes the ambiguity
between namespaces and the dependence on the collections keyword's search list, which is why it is
the right default in reproducible content. It does not remove path-order dependence altogether: if two roots in
collections_path each hold a demo.audit, the first root wins, and the FQCN tells you
nothing about which version you got. ansible-galaxy collection list and
ansible-doc are what settle that.
The negative case: a clean environment with nothing installed
Copy play.yml and hosts.ini into a fresh directory with no adjacent
collections/, give it a config file that does not set
collections_path, and point the environment at an empty root. This is expected to fail, and the
failure is the evidence that the earlier success came from the pin rather than from something already installed
on the machine.
Use mktemp -d for both directories rather than fixed paths: a path you picked by hand may already
contain a collection from an earlier experiment, which would quietly invalidate the test. The two directories
created here are the only ones removed at the end — do not point the cleanup at anything you did not just
create.
CLEAN_DIR=$(mktemp -d)
EMPTY_ROOT=$(mktemp -d)
cp play.yml hosts.ini "$CLEAN_DIR/"
printf '[defaults]\ninterpreter_python = auto_silent\n' > "$CLEAN_DIR/ansible.cfg"
cd "$CLEAN_DIR"
ANSIBLE_CONFIG=ansible.cfg \
ANSIBLE_COLLECTIONS_PATH="$EMPTY_ROOT" \
ANSIBLE_COLLECTIONS_SCAN_SYS_PATH=false \
~/tma-collections/.venv/bin/ansible-playbook -i hosts.ini play.yml
cd ~
rm -rf "$CLEAN_DIR" "$EMPTY_ROOT"
Expected result — the play fails and the process exits non-zero:
TASK [The filter from demo.audit 1.0.0 is callable by its full name] *****
[ERROR]: Task failed: Syntax error in expression:
No filter named 'demo.audit.audit_label'.
localhost : ok=0 changed=0 unreachable=0 failed=1
ANSIBLE_COLLECTIONS_SCAN_SYS_PATH=false is the third root you have to close off. It defaults to
true, and when it is on, ansible-core also scans sys.path for installed
ansible_collections packages — so a collection shipped as a Python package in the same virtual
environment would still resolve even with an empty ANSIBLE_COLLECTIONS_PATH and no adjacent
directory.
No filter named is the generic message for a plugin that did not resolve, and it is worth recognising:
it means a lookup failed, not that your expression is malformed. Run
ansible-galaxy collection list in the same directory and with the same environment to see which
roots were actually searched.
External collections, when you need them
For collections you do not build yourself, the same two rules apply: pin with ==, and keep the
artefact if you need the result to be identical later. The structure of an entry looks like this — the version
here is a placeholder, so look up and record the version you actually tested rather than copying
this number:
---
collections:
# Replace X.Y.Z with a version you have installed and tested.
- name: community.general
version: "==X.Y.Z"
source: https://galaxy.ansible.com
- name: ./dist/demo-audit-1.0.0.tar.gz
type: file
To take the resolution offline entirely, fetch the artefacts on a connected machine and install from them on the
air-gapped one. ansible-galaxy collection download -r requirements.yml -p ./downloads writes the
tarballs to a directory you choose; upstream also documents downloading a tarball straight from a collection's
page on Galaxy, and notes that you may need to fetch dependent collections yourself. Either way, the tarballs are
then installed exactly as demo.audit was above. If you want signature verification as well, the
signatures key in requirements.yml accepts URIs of detached signatures and requires
--keyring.
Finally, a caution on dependency metadata as evidence. A collection's requires_ansible range and a
role's min_ansible_version state what the author claimed, often years ago. A low minimum is
not proof of compatibility with a current release, and a missing upper bound is not a promise. Test against the
core version you pinned.
Troubleshooting
-
"No filter named …" or "couldn't resolve module/action". The collection did not resolve. Run
ansible-galaxy collection listandansible-config dump | grep -i collectionsfrom the same directory, and remember the playbook-adjacent path. -
The wrong version is loading. Only one version of a collection can be installed per root,
but you may have several roots.
collection listprints each root separately; remove the stale copy rather than reinstalling over it. -
An install succeeded but the version moved. Check for a range identifier instead of
==, or atype: dir/type: gitbranch entry. -
"does not have requires_ansible metadata". Harmless for a local demo; for real content, add
meta/runtime.yml. -
-pand the config disagree. Upstream advises passing a path that is already one of the configured roots. Installing somewhere unlisted succeeds and then the content is not found at run time. - A requirements file with both roles and collections and a custom path. Upstream documents that this combination does not work: collections are skipped and every entry is processed as a role install. Split the file.
Related reading
- Collections — namespaces, FQCNs and the
collectionskeyword. - Ansible Galaxy — discovering and installing published content.
- Custom modules — writing the plugins a collection ships.
- Execution environments — the container-image answer to the same problem.
- Ansible Galaxy: finding and using roles — the discovery-side guide this one complements.
Sources
-
Installing collections
— install paths, playbook-adjacent collections, signature verification, and the
-pguidance. Accessed 2026-11-25. - Installing an older version of a collection — the range identifier list and the "most recent match" rule. Accessed 2026-11-25.
-
Install multiple collections with a requirements file
— the
name,version,signatures,sourceandtypekeys, and the roles-plus-collections caveat. Accessed 2026-11-25. -
Downloading a collection for offline use
—
ansible-galaxy collection download. Accessed 2026-11-25. -
Verifying collections
— what
collection verifycompares, the online versus--offlineforms, and signature verification. Accessed 2026-11-25. -
ansible-core 2.22.0 base configuration
—
COLLECTIONS_PATHSwith ini keycollections_pathand envANSIBLE_COLLECTIONS_PATH,COLLECTIONS_SCAN_SYS_PATH, andcollections_on_ansible_version_mismatch. Accessed 2026-11-25.