Ansible Galaxy: Install, Create & Share Roles and Collections (Guide)
By Luca Berton · Published 2024-01-01 · Category: installation
Complete guide to Ansible Galaxy. Install roles and collections, create your own, publish to Galaxy, manage requirements.yml. Practical command-line examples.

What Is Ansible Galaxy?
Ansible Galaxy is the community hub for finding, sharing, and downloading Ansible roles and collections. Think of it as the npm/PyPI for Ansible — a registry of reusable automation content.
See also: Ansible Galaxy: Install Collections & Roles — Complete Guide (2026)
Galaxy Website vs CLI
- galaxy.ansible.com — Web interface to browse and search content
- ansible-galaxy — CLI tool to install and manage content locally
Roles vs Collections
| Feature | Roles | Collections |
|---|---|---|
| Contains | Tasks, handlers, vars, templates, files | Modules, roles, plugins, docs |
| Namespace | author.role_name | namespace.collection |
| Install | ansible-galaxy role install | ansible-galaxy collection install |
| Distribution | Galaxy, Git | Galaxy, Automation Hub |
| Standard since | Ansible 1.x | Ansible 2.9+ |
Installing Content from Galaxy
Install a Role
# Install from Galaxy
ansible-galaxy role install geerlingguy.docker
# Install specific version
ansible-galaxy role install geerlingguy.docker,6.1.0
# Install to custom path
ansible-galaxy role install geerlingguy.docker -p ./roles/
# Install from Git
ansible-galaxy role install git+https://github.com/user/repo.gitInstall a Collection
# Install from Galaxy
ansible-galaxy collection install community.general
# Install specific version
ansible-galaxy collection install community.general:9.0.0
# Install from Automation Hub
ansible-galaxy collection install ansible.netcommon \
--server https://console.redhat.com/api/automation-hub/
# Install from tarball
ansible-galaxy collection install community-general-9.0.0.tar.gzRequirements File
Create requirements.yml for reproducible installs:
---
roles:
- name: geerlingguy.docker
version: "6.1.0"
- name: geerlingguy.nginx
- src: https://github.com/user/custom-role.git
version: main
collections:
- name: community.general
version: ">=9.0.0"
- name: ansible.posix
- name: community.dockerInstall everything:
ansible-galaxy install -r requirements.yml
ansible-galaxy collection install -r requirements.ymlSee also: Ansible Creator CLI: Scaffold Collections, Roles & Projects (v26.4.0)
Most Popular Collections
| Collection | Purpose | Modules |
|---|---|---|
community.general | General-purpose modules | 200+ |
ansible.builtin | Core modules (included) | 70+ |
ansible.posix | POSIX system management | 20+ |
community.docker | Docker management | 15+ |
amazon.aws | AWS cloud modules | 100+ |
azure.azcollection | Azure modules | 80+ |
community.vmware | VMware management | 150+ |
community.windows | Windows modules | 50+ |
ansible.netcommon | Network automation base | 20+ |
community.kubernetes | K8s management | 10+ |
Most Popular Roles
| Author | Role | Purpose |
|---|---|---|
| geerlingguy | docker | Install Docker |
| geerlingguy | nginx | Install/configure nginx |
| geerlingguy | java | Install Java |
| geerlingguy | postgresql | PostgreSQL server |
| geerlingguy | security | Linux security hardening |
| robertdebock | bootstrap | System bootstrapping |
Creating Your Own Role
# Generate role skeleton
ansible-galaxy role init my_role
# Directory structure created:
my_role/
├── README.md
├── defaults/
│ └── main.yml # Default variables (lowest priority)
├── files/ # Static files
├── handlers/
│ └── main.yml # Handlers
├── meta/
│ └── main.yml # Role metadata (dependencies, platforms)
├── tasks/
│ └── main.yml # Main task list
├── templates/ # Jinja2 templates
├── tests/
│ ├── inventory
│ └── test.yml
└── vars/
└── main.yml # Role variables (high priority)Using Your Role
---
- name: Apply my role
hosts: webservers
roles:
- my_role
- role: my_role
vars:
port: 8080Creating a Collection
# Create collection skeleton
ansible-galaxy collection init my_namespace.my_collection
# Structure:
my_namespace/my_collection/
├── docs/
├── galaxy.yml # Collection metadata
├── meta/runtime.yml
├── plugins/
│ ├── modules/ # Custom modules
│ ├── filter/ # Filter plugins
│ └── lookup/ # Lookup plugins
├── roles/ # Bundled roles
└── README.md
# Build the collection
ansible-galaxy collection build
# Publish to Galaxy
ansible-galaxy collection publish my_namespace-my_collection-1.0.0.tar.gzSee also: Ansible Bullhorn #223: ansible-core Releases, New Collections & AI Collaboration
Managing Installed Content
# List installed roles
ansible-galaxy role list
# List installed collections
ansible-galaxy collection list
# Remove a role
rm -rf ~/.ansible/roles/geerlingguy.docker
# Verify collection
ansible-galaxy collection verify community.generalBest Practices
- Pin versions in
requirements.ymlfor reproducibility - Use collections over standalone roles for new projects
- Check Galaxy ratings and downloads before installing
- Vendor dependencies for air-gapped environments
- Use Automation Hub for certified, supported content (AAP)
- Keep requirements.yml in version control
- Test roles with Molecule before publishing
FAQ
Is Ansible Galaxy free?
Yes. The Galaxy website and CLI are free to use. Automation Hub (certified content) requires an AAP subscription.What is the difference between Galaxy and Automation Hub?
Galaxy is community-maintained (anyone can publish). Automation Hub provides Red Hat-certified and supported content for enterprise customers.Where are Galaxy roles installed?
Default:~/.ansible/roles/. Override with -p flag or roles_path in ansible.cfg.
How do I use a collection module in a playbook?
Use the FQCN:community.general.timezone instead of just timezone.
Conclusion
Ansible Galaxy is essential for productive Ansible automation. Don't reinvent the wheel — leverage the thousands of community roles and collections available.
For more tutorials, visit AnsiblePilot.
Install a Role
ansible-galaxy role install geerlingguy.docker
ansible-galaxy role install geerlingguy.nginx --roles-path ./rolesInstall a Collection
ansible-galaxy collection install community.general
ansible-galaxy collection install amazon.aws
ansible-galaxy collection install community.docker --forceRequirements File
# requirements.yml
---
roles:
- name: geerlingguy.docker
version: "7.4.0"
- name: geerlingguy.nginx
collections:
- name: community.general
version: ">=9.0.0"
- name: amazon.aws
- name: community.dockeransible-galaxy install -r requirements.yml
ansible-galaxy collection install -r requirements.ymlSearch Galaxy
ansible-galaxy role search nginx
ansible-galaxy role info geerlingguy.nginx
ansible-galaxy collection list # Show installedUse Roles in Playbooks
- hosts: webservers
become: true
roles:
- geerlingguy.docker
- role: geerlingguy.nginx
vars:
nginx_vhosts:
- listen: "80"
server_name: "example.com"Use Collections
- hosts: all
tasks:
# FQCN (recommended)
- community.general.timezone:
name: UTC
# Or with collections keyword
- ansible.builtin.debug:
msg: "Using builtin"Create Your Own Role
ansible-galaxy role init my_rolemy_role/
├── README.md
├── defaults/main.yml # Default variables
├── files/ # Static files
├── handlers/main.yml # Handlers
├── meta/main.yml # Role metadata
├── tasks/main.yml # Main tasks
├── templates/ # Jinja2 templates
├── tests/
└── vars/main.yml # Role variablesCreate a Collection
ansible-galaxy collection init myorg.mytoolsmyorg/mytools/
├── galaxy.yml # Collection metadata
├── plugins/
│ ├── modules/ # Custom modules
│ ├── filters/ # Custom filters
│ └── lookup/ # Lookup plugins
├── roles/ # Bundled roles
├── playbooks/ # Playbooks
└── docs/Publish to Galaxy
# Build collection
ansible-galaxy collection build
# Publish
ansible-galaxy collection publish myorg-mytools-1.0.0.tar.gz --api-key YOUR_KEYPrivate Repositories
# ansible.cfg
[galaxy]
server_list = private_hub, galaxy
[galaxy_server.private_hub]
url = https://hub.internal.com/api/galaxy/
token = your-token
[galaxy_server.galaxy]
url = https://galaxy.ansible.com/Popular Collections
| Collection | Purpose |
|---|---|
community.general | General utilities |
amazon.aws | AWS management |
community.docker | Docker automation |
ansible.posix | POSIX systems |
ansible.windows | Windows management |
community.mysql | MySQL/MariaDB |
community.postgresql | PostgreSQL |
ansible.netcommon | Network common |
FAQ
Roles vs Collections?
Roles bundle tasks/templates for a single purpose. Collections bundle roles, modules, plugins, and playbooks as a distribution package.
How do I pin versions?
In requirements.yml: version: "==2.0.0" for exact, version: ">=2.0.0,<3.0.0" for range.
Offline installation?
# Download
ansible-galaxy collection download community.general -p ./offline/
# Install from local
ansible-galaxy collection install ./offline/community-general-9.0.0.tar.gzInstall a Role
ansible-galaxy role install geerlingguy.docker
ansible-galaxy role install geerlingguy.nginxInstall a Collection
ansible-galaxy collection install community.docker
ansible-galaxy collection install amazon.aws
ansible-galaxy collection install community.generalRequirements File
# requirements.yml
---
roles:
- name: geerlingguy.docker
version: "7.4.0"
- name: geerlingguy.nginx
collections:
- name: community.docker
version: ">=4.0.0"
- name: amazon.aws
- name: community.general
- name: ansible.posixansible-galaxy install -r requirements.yml
ansible-galaxy collection install -r requirements.ymlList Installed
ansible-galaxy role list
ansible-galaxy collection listUse in Playbook
# Use a role
- hosts: all
roles:
- geerlingguy.docker
# Use a collection module
- hosts: all
tasks:
- community.docker.docker_container:
name: nginx
image: nginx:latestCreate Your Own Role
ansible-galaxy role init my_role
# Creates:
# my_role/
# ├── defaults/main.yml
# ├── handlers/main.yml
# ├── meta/main.yml
# ├── tasks/main.yml
# ├── templates/
# ├── files/
# └── vars/main.ymlCreate Your Own Collection
ansible-galaxy collection init myorg.mycollection
# Creates:
# myorg/mycollection/
# ├── galaxy.yml
# ├── plugins/
# ├── roles/
# └── docs/Publish to Galaxy
# Build collection
ansible-galaxy collection build
# Publish
ansible-galaxy collection publish myorg-mycollection-1.0.0.tar.gz --api-key $GALAXY_API_KEYPrivate Galaxy (Automation Hub)
# ansible.cfg
[galaxy]
server_list = automation_hub, galaxy
[galaxy_server.automation_hub]
url = https://hub.example.com/api/galaxy/content/published/
token = my-token
[galaxy_server.galaxy]
url = https://galaxy.ansible.com/Install from Git
# requirements.yml
roles:
- src: https://github.com/myorg/my-role.git
version: main
name: my-role
collections:
- name: https://github.com/myorg/my-collection.git
type: git
version: mainFAQ
roles vs collections?
Roles are bundles of tasks/templates/handlers. Collections are broader packages that include roles, modules, plugins, and playbooks. Collections are the modern standard.
Where are they installed?
Roles: ~/.ansible/roles/. Collections: ~/.ansible/collections/. Override with ANSIBLE_ROLES_PATH / COLLECTIONS_PATHS.
How to pin versions?
Always pin in requirements.yml for reproducible builds. Use version: ">=4.0.0,<5.0.0" for flexible pinning.
Related Articles
Category: installation