Safeguard
Supply Chain•

How do you pin Ansible collections and roles in requirements.yml?

Pin Ansible collections with a version or range in requirements.yml. Roles take exact versions only. See the syntax and a review checklist for the file.

Safeguard Security Team
3 min read

Pin each entry in requirements.yml to an exact version. Collections accept a version or a range, defaulting to any version, while the documentation notes that ranges are not supported for roles. A pinned file turns your dependency list into something you can review.

What the file looks like

collections:
  - name: my_namespace.my_collection
    version: "1.2.0"
  - name: my_namespace.other_collection
    version: ">=1.2.0"
roles:
  - name: example.java
    version: "1.9.6"

The same format can list a role and a collection together. The version field for collections takes a version range identifier and defaults to *, meaning any. You can also give a source to pull a collection from a particular server.

Why pinning matters

Without a pin, the next install gets whatever is current. A change in a collection you depend on can enter a run with no change in your own repository. A range like >=1.2.0 has the same problem in a milder form.

Pin choices

EntryEffectReview burden
No versionLatest at install timeHard to reason about
RangeAnything in the rangeMedium
Exact versionOne versionLowest, but you must update by pull request
Exact version plus signaturesOne version and key checkedLowest

Add signatures for extra assurance

Entries can include a signatures list. That ties into the keyring workflow: Ansible checks the listed detached signatures, in addition to those the server provides. See the separate post on signed collections for the limits, which include Git and tar based installs.

Review checklist

  1. Every entry has an exact version.
  2. Every entry has a source you recognize, and a source key when you use a private server.
  3. Entries from Git or URLs are flagged, since signature verification does not cover them.
  4. Dependencies of dependencies are checked, since the verify command does not include them.
  5. Updates arrive as pull requests with release notes linked.

Keep a record

Treat the file as your inventory of automation dependencies. Store it in version control, and note which playbooks use which collections. When an advisory appears, you can answer which control nodes and pipelines are affected.

Quick check

Can I use a version range for roles?

The documentation says ranges are not supported for roles. Pin an exact version.

What is the default version for a collection?

Any version, written as an asterisk.

Where do I list roles?

Under the roles key in the same requirements file.

Safeguard offers SBOM and dependency scanning and policy gates that can block a pull request on findings, and you can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.