A lockfile for Ansible collections

In June a customer's nightly job started failing at one task. Their playbook repository had not changed in three weeks. The task used a module from community.general, and their requirements.yml said version: ">=9.0.0". The collection had shipped a new minor release that tightened input validation, and the project sync on the control plane had quietly pulled it in. The playbook was fine. The environment was not the one they had tested.

This is a lockfile problem. Python and JavaScript solved it long ago, and the Ansible world is catching up. Here is what we do.

1. Exact versions, always

collections/requirements.yml
collections:
  - name: community.general
    version: 9.5.0
  - name: ansible.posix
    version: 1.6.0
  - name: kubernetes.core
    version: 5.0.0

No ranges, no latest, no omitted version. A pull request that adds a collection without a pinned version fails CI.

2. Do not install at job time

AWX has a project setting that downloads collections listed in requirements.yml every time the project syncs. It is convenient and we turn it off for production templates. Collections arrive inside the execution environment instead, built once and tagged:

execution-environment.yml
version: 3
images:
  base_image:
    name: ee-base:2026.07
dependencies:
  ansible_core:
    package_pip: ansible-core==2.16.9
  ansible_runner:
    package_pip: ansible-runner
  galaxy: collections/requirements.yml
  python: requirements.txt
  system: bindep.txt
$ ansible-builder build --tag ee-platform:2026-07-08 --container-runtime podman

The tag is date-based and immutable. Job templates refer to a specific tag, and to the digest behind it for anything that matters. Rolling back a bad collection upgrade is a one-line change in the template instead of an archaeology project.

3. Check what is actually in the image

Pinning in a file only helps if the file and the image agree. A CI job runs the finished image and compares:

$ podman run --rm ee-platform:2026-07-08 \
    ansible-galaxy collection list --format json > installed.json
$ python3 tools/compare_lock.py collections/requirements.yml installed.json

The comparison script is 30 lines. It fails on any collection that is present but unpinned, pinned but missing, or at a different version. Python packages pulled in by a collection show up in the image too, and you want to know about those just as much.

4. Vendoring for the cautious

Some customers cannot reach a public Galaxy server from their build environment, and some do not want to. For them:

$ ansible-galaxy collection download -r collections/requirements.yml -p vendor/collections
$ sha256sum vendor/collections/*.tar.gz > vendor/collections/SHA256SUMS

The tarballs go into the repository (they are small), the checksums are reviewed in the pull request, and the build installs from the local path with ansible-galaxy collection install -r vendor/collections/requirements.yml. It is dull, which is the point.

5. Bumping on purpose

A weekly job opens a pull request per collection that has a newer release. It builds a candidate image, runs the repository's --check mode tests against a staging inventory, and attaches the changelog of the collection as the description. Someone reads the changelog. Most weeks the answer is to merge. Some weeks it is "this changes a default, schedule it for the first of the month". The decision is visible, reviewed and reversible.

What it costs

A pipeline to maintain, and about 90 seconds per template run of extra pull time if the node has not cached the image yet. In return, for the 38 tenants that have adopted it since March, we have had zero incidents of the original kind. The one drift-related ticket since then was a tenant that kept a template pointed at :latest, and we have since added a check for that too.

If you want the compare script or an execution-environment.yml tailored to your setup, ask support. We would rather you had it.


Written by Elena Kovac. Comments, corrections and arguments to elena.kovac@ansiblecloud.io.