Lesson 17 / 26
Collections and Ansible Galaxy
Install shared content and pin versions with a requirements file.
Do not reinvent
Modern Ansible content is distributed as collections: bundles of modules, plugins and roles, named namespace.collection (for example community.general or amazon.aws). Ansible Galaxy and Red Hat's Automation Hub host them. List what your project needs in requirements.yml with versions and install with ansible-galaxy collection install -r requirements.yml, so every developer and CI job uses the same content. Review third-party roles before using them, since they run with your privileges.
requirements.yml
Pinning versions makes runs reproducible. Version numbers here are examples.
---
collections:
- name: community.general
version: ">=9.0.0,<10.0.0"
- name: ansible.posix
roles:
- name: geerlingguy.nginx
version: "3.2.0"Check module docs locally
ansible-doc ansible.builtin.copy shows documentation for the exact module version you have installed, including examples, with no internet needed.
Quick check: Why pin collection versions in requirements.yml?
- Collections cannot be installed otherwise
- Pinning makes modules faster
- So every run uses the same, reproducible content
- It hides the code
Answer
So every run uses the same, reproducible content — Unpinned updates can change behaviour unexpectedly between runs.