Ansible Tutorial · Configuration Management · Lesson 14 of 20
Ansible Galaxy
Install and manage community roles and collections.
What is Ansible Galaxy?
Ansible Galaxy is both a public registry (galaxy.ansible.com) and a CLI tool (ansible-galaxy) for
sharing reusable Ansible content. You can install community-maintained roles and collections (bundles
of roles, modules and plugins).
Installing a role
ansible-galaxy role install geerlingguy.docker
This downloads the role to ~/.ansible/roles/ (or the configured roles_path).
requirements.yml — pin your dependencies
# requirements.yml
roles:
- name: geerlingguy.docker
version: "7.4.1"
- name: geerlingguy.nginx
version: "3.2.0"
collections:
- name: community.general
version: ">=9.0.0,<10.0.0"
- name: community.docker
version: "3.12.2"
- name: ansible.posix
version: "1.6.0"
Install everything at once:
ansible-galaxy install -r requirements.yml
Always pin versions in requirements.yml for reproducible builds. Without a version, you get the
latest, which may break your playbooks.
Collections vs roles
| Feature | Role | Collection |
|---|---|---|
| Contains | Tasks, handlers, templates, vars | Roles + modules + plugins + docs |
| Namespace | author.rolename |
namespace.collection |
| Install | ansible-galaxy role install |
ansible-galaxy collection install |
| Since | Ansible 1.x | Ansible 2.9+ |
Collections are the modern packaging format. When you install community.general, you get modules like
community.general.timezone, community.general.ufw and community.general.ini_file.
Using collection modules
After installing a collection, reference its modules by their fully qualified name:
- name: Set timezone
community.general.timezone:
name: UTC
- name: Allow SSH through firewall
community.general.ufw:
rule: allow
port: "22"
proto: tcp
Useful collections
| Collection | Provides |
|---|---|
community.general |
500+ general-purpose modules |
community.docker |
Docker container and image management |
community.postgresql |
PostgreSQL database management |
ansible.posix |
POSIX system modules (sysctl, mount, at) |
amazon.aws |
AWS cloud modules |
google.cloud |
GCP cloud modules |
Offline / CI environments
In CI or air-gapped environments, download collections as tarballs and install from the local file:
ansible-galaxy collection download community.general -p ./collections/
ansible-galaxy collection install ./collections/community-general-9.5.0.tar.gz
ansible-galaxy role list 2>/dev/null | head -5
Output
# /home/user/.ansible/roles - geerlingguy.docker, 7.4.1 - geerlingguy.nginx, 3.2.0
Run this on your computer — see “Get Started” for setup.
ansible-galaxy collection list 2>/dev/null | head -10
Output
# /home/user/.ansible/collections/ansible_collections Collection Version ------------------------ ------- amazon.aws 9.0.0 ansible.netcommon 7.1.0 ansible.posix 1.6.0 ansible.utils 5.1.2 community.docker 3.12.2 community.general 9.5.0
Run this on your computer — see “Get Started” for setup.
Test yourself
What is the modern packaging format for Ansible content?
RolesCollectionsModulesPlugins
Show answer
Answer: Collections
Collections bundle roles, modules, and plugins together and are the modern packaging format since Ansible 2.9. They use a namespace.collection naming convention.