Introduction to Ansible Galaxy
What is Ansible Galaxy?
Ansible Galaxy is a community repository for Ansible roles, which are reusable units of automation that can be shared and downloaded. Galaxy allows you to find, use, and share Ansible roles to streamline your automation tasks.
Installing Ansible Galaxy
Ansible Galaxy is included with Ansible by default. If you have Ansible installed, you already have access to Ansible Galaxy. To check if Ansible is installed, run the following command:
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.7.5 (default, Nov 20 2019, 09:21:52) [GCC 8.3.0]
Using Ansible Galaxy
To use Ansible Galaxy, you can perform various tasks such as installing roles, searching for roles, and uploading roles. Below are some common commands and their usage:
Installing Roles
To install a role from Ansible Galaxy, use the following command:
For example, to install the geerlingguy.apache
role:
- downloading role from https://github.com/geerlingguy/ansible-role-apache/archive/2.0.0.tar.gz
- extracting geerlingguy.apache to /home/user/.ansible/roles/geerlingguy.apache
- geerlingguy.apache (2.0.0) was installed successfully
Searching for Roles
You can search for roles on Ansible Galaxy using the following command:
For example, to search for roles related to apache
:
- geerlingguy.apache (2.0.0) [Apache HTTP Server]
- ANXS.apache (1.0.0) [Apache Server Role for Ansible]
- Oefenweb.apache (1.2.3) [Apache role]
Creating and Sharing Roles
Creating your own roles allows you to modularize your automation scripts and share them with others. Here's a basic structure for an Ansible role:
├── README.md ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── templates └── vars └── main.yml
Once you have created your role, you can share it on Ansible Galaxy. First, make sure you have an account on Ansible Galaxy. Then, follow these steps:
- Initialize a new Git repository for your role.
- Push your role to a public GitHub repository.
- Import your role into Ansible Galaxy by linking your GitHub account.
Conclusion
Ansible Galaxy is a powerful tool that simplifies the process of sharing and using Ansible roles. By leveraging Galaxy, you can save time and effort by reusing community-contributed roles and sharing your own creations with others. Whether you're just getting started with Ansible or you're an experienced user, Ansible Galaxy is a valuable resource for enhancing your automation workflows.