Ansible Galaxy is a community hub for sharing and finding Ansible roles and collections, making it easier for users to automate their IT processes efficiently. It allows users to leverage pre-built automation scripts, which can save time and effort in configuration management. Current stable version: Ansible-core 2.20.2 (released January 29, 2026). Galaxy now primarily focuses on Collections, which are the modern way to distribute Ansible content.
Make sure you have Ansible installed on your system.
Setup Ansible on Linux or MacOS
Set up a directory for your Ansible project:
mkdir my_ansible_project
cd my_ansible_project
You can search for roles and collections using the Galaxy website Ansible Galaxy or by using the command line:
ansible-galaxy search <search_term>
To install a specific collection, use the following command:
ansible-galaxy collection install <namespace.collection_name>
For example:
ansible-galaxy collection install community.general
ansible-galaxy collection install ansible.posix
To install a specific role, use the following command:
ansible-galaxy role install <role_name>
For example:
ansible-galaxy role install geerlingguy.apache
This will download the role and place it in the roles/ directory of your project.
Create a requirements.yml file for collections:
---
collections:
- name: community.general
version: ">=6.0.0,<7.0.0"
source: https://galaxy.ansible.com
- name: ansible.posix
version: ">=1.4.0"
- name: community.docker
version: ">=3.0.0"
Install collections from the requirements file:
ansible-galaxy collection install -r requirements.yml
Create a requirements.yml file for roles:
---
- src: geerlingguy.apache
version: "3.0.0"
- src: geerlingguy.mysql
version: "4.0.0"
Install roles from the requirements file:
ansible-galaxy role install -r requirements.yml
When using collections, reference modules with the full namespace:
---
- name: Example using collection modules
hosts: all
become: true
tasks:
- name: Use a module from community.general
community.general.ntp:
state: present
server: pool.ntp.org
when: ansible_os_family == "RedHat"
- name: Use a module from ansible.posix
ansible.posix.firewalld:
service: http
permanent: true
state: enabled
Create a playbook file (e.g., site.yml) and include the installed role:
---
- hosts: all
become: true
roles:
- geerlingguy.apache
Run your playbook using the ansible-playbook command:
ansible-playbook site.yml
Use the following command to create a new collection skeleton:
ansible-galaxy collection init my_namespace.my_collection
This will create a directory structure for your collection.
Use the following command to create a new role:
ansible-galaxy role init my_new_role
This will create a directory structure for your role.
Edit the files in the created directory to define tasks, handlers, and other configurations.
If you want to share your collection on Ansible Galaxy, follow these steps:
Create proper metadata in galaxy.yml with information about the collection.
Build the collection:
ansible-galaxy collection build
Upload to Galaxy:
ansible-galaxy collection publish my_namespace-my_collection-1.0.0.tar.gz
If you want to share your role on Ansible Galaxy:
Create a meta/main.yml file in your role directory with metadata about the role.
Upload to Galaxy:
ansible-galaxy import <github_username> <repository_name>
# List installed collections
ansible-galaxy collection list
# List installed roles
ansible-galaxy role list
# Update all collections
ansible-galaxy collection install -r requirements.yml --force
# Update all roles
ansible-galaxy role install -r requirements.yml --force
You can configure Ansible Galaxy to work with private servers:
# Configure a private Galaxy server
ansible-config dump | grep COLLECTIONS_PATHS
In your ansible.cfg:
[galaxy]
server_list = my_server
[galaxy_server.my_server]
url = https://galaxy.example.com
Any questions?
Feel free to contact us. Find all contact information on our contact page.