Ansible Galaxy: Complete Guide to Collections, Roles, and Publishing
By Luca Berton · Published 2024-01-01 · Category: installation
Master Ansible Galaxy: install collections and roles, manage dependencies, create and publish your own content, use requirements.yml, configure private Galaxy servers, and integrate with Automation Hub.
What Is Ansible Galaxy?
Ansible Galaxy is the community hub for sharing Ansible content — collections and roles that you can download and use in your automation. Think of it as npm for Ansible.
• Galaxy website:
Install Collections
From Galaxy
From requirements.yml
From Private Galaxy Server
Install Roles
Role requirements.yml
Create a Collection
Scaffold
galaxy.yml
Add a Custom Module
Add a Custom Filter
Usage:
Add a Role to Collection
Build and Publish
Build
Publish to Galaxy
Publish to Automation Hub
Publish to Private Galaxy (Pulp)
Create a Role
Role meta/main.yml
Dependency Management
Pin Versions for Reproducibility
Use Collections Path
Search Galaxy
FAQ
What's the difference between collections and roles?
Collections are the modern packaging format that can contain modules, plugins, roles, and playbooks in a single distributable unit. Roles contain only tasks, handlers, files, templates, and variables. Collections replaced standalone roles as the recommended distribution method.
How do I choose between Galaxy and Automation Hub?
Galaxy is free and community-maintained — anyone can publish. Automation Hub is Red Hat's curated repository with certified, supported content included with AAP subscriptions. Use Galaxy for community content and Automation Hub for enterprise-supported content.
Should I use ansible-galaxy install or ansible-galaxy collection install?
Use ansible-galaxy collection install for collections and ansible-galaxy role install for standalone roles. The plain ansible-galaxy install with a requirements.yml handles both if your file has both collections: and roles: sections.
How do I keep collections updated?
Run ansible-galaxy collection install -r requirements.yml --force periodically. For CI/CD, pin exact versions in requirements.yml and update deliberately. Use Dependabot or Renovate to automate version bump PRs.
Can I host a private Galaxy server?
Yes. Use Pulp with the galaxy_ng plugin or Automation Hub (included with AAP). Private Galaxy servers let you host proprietary collections, mirror public content, and control what's available to your organization.
Conclusion
Ansible Galaxy is the ecosystem that makes Ansible powerful — thousands of community collections and roles ready to use. Install content with ansible-galaxy collection install, pin versions in requirements.yml for reproducibility, create your own collections with custom modules and filters, and publish to Galaxy or a private server. For enterprise content with Red Hat support, use Automation Hub alongside Galaxy.
Related Articles • Ansible Collections: Install, Use, and Create • Ansible Roles Complete Guide • Ansible Documentation Complete Guide • Ansible Lint Complete Guide • Install Ansible Complete Guide • Introducing the New Ansible Galaxy • Crafting and Publishing Custom Collections on Automation Hub
Category: installation