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. Here’s a step-by-step guide on how to use Ansible Galaxy:
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 using the Galaxy website Ansible Galaxy or by using the command line:
ansible-galaxy search <search_term>
To install a specific role, use the following command:
ansible-galaxy install <role_name>
For example:
ansible-galaxy install lsa.apache
This will download the role and place it in the roles/ directory of your project.
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
You can also create your own roles to share with the community:
Use the following command to create a new role:
ansible-galaxy 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 role on Ansible Galaxy, you can publish it. First, ensure you have an account on the Galaxy website, then follow these steps:
Create a galaxy.yml file in your role directory with metadata about the role.
Package the role:
ansible-galaxy role package my_new_role
Upload to Galaxy:
ansible-galaxy login
ansible-galaxy role upload my_new_role.tar.gz
To update an installed role to the latest version, use:
ansible-galaxy install <role_name> --force
Feel free to contact us. Find all contact information on our contact page.