In this article, we will learn that what is the difference between Ansible and Ansible Galaxy (Ansible vs Ansible Galaxy).
Ansible is an open-source configuration management tool. It helps in automating software provisioning, configuration management, and application deployment.
As you learn more about Ansible, you will surely encounter Ansible Galaxy. However, people often fail to truly understand what this Ansible Galaxy is. Let us see the difference between the two!
Ansible vs Ansible Galaxy
Ansible is an open-source configuration management tool while Ansible Galaxy is a repository for Ansible roles. Ansible Galaxy for Ansible is what PyPI is for Python, or what Maven is for Java.
It is an open-source configuration management tool that automates software provisioning, configuration management, and application deployment. It lets you control and configure machines from a single server machine. It uses a push-based mechanism where the configuration is “pushed” from the master machine to all its nodes.
Configurations are written in YAML and are very simple and human-readable which makes it easier for the server admin to write and understand the tasks.
It operates over SSH and relies on the most secure transport layer, which is OpenSSH. Moreover, all the Ansible configurations are defined in a group of YAML file which we call playbook. Plays (or tasks) are written inside this playbook. A task uses a module to configure nodes. If you want to know about some commonly used modules, click here.
Configurations are written inside a file called playbook. Whatever tasks we write in a playbook, gets executed in the same order. It also supports executing tasks both synchronously and asynchronously. In the above picture, you can see a bunch of host machines. All the configurations we define are performed on these host machines.
The Advantages of Ansible:
- Free: It is open-source.
- Simple: No problems in setting up and using Ansible.
- Powerful: Using Ansible you can even configure thousands of machines at a time.
- Flexible: It supports multiple environments.
- Agentless: Doesn’t rely on any agent nodes like other tools such as Jenkins.
- Efficient: It is light on your server as it doesn’t need any other software to run.
Ansible Galaxy is a repository where users can share and fetch roles. Ansible Galaxy promotes reusable roles for server configuration. It is very common to use Ansible Galaxy in a project.
Roles are a way of breaking bigger playbooks into a systematic structure.
We can modify our own roles and use them accordingly. You can view more of these roles by visiting this galaxy https://galaxy.ansible.com/
Ansible Role Structure and its significance
- README.md – This is the Readme file for the role. Put the detailed information of all the input parameters for the role and example yml in the readme file.
- tasks – You can enlist all tasks to be executed by the Role in tasks. Main.yml of the tasks is the entry point for the Role (this is where the execution starts). One can include other files into this file.
- handlers – Contains handlers, which may be used by this role or even anywhere outside this role.
- defaults – Default variables for the Role.
- vars – Other variables which are of more priority than the defaults for Role.
- files – This contains the files which can be deployed via Role.
- templates – Contains templates which can be deployed via Role.
- meta – You can define metadata for the Role in meta. Other Role dependencies, if any, should be mentioned in this file.
- tests – CI tests to be executed.
- library – Embedding Modules and Plugins in Roles (Not created by init command). If required one can define custom module in python in this folder and use it in the tasks.
How To Create Roles With Ansible Galaxy?
As discussed above, Ansible Galaxy is essentially a large public repository of Ansible roles and it is constantly evolving and increasing.
You can initialize a new galaxy role using:
You can also install a role directly from the Ansible Galaxy role store by executing the command:
ansible-galaxy install <name of role>
Here are some commonly used
ansible-galaxy commands you will need:
ansible-galaxy list-> Displays a list of installed roles, with version numbers.
ansible-galaxy remove <role>-> Removes an installed role.
ansible-galaxy info-> Provides a variety of information about Ansible Galaxy.
ansible-galaxy init-> It creates a role template suitable for submission to Ansible Galaxy.
I hope this article helped you understand the use-cases of both Ansible and Ansible Galaxy. If you liked this article, do share it with your friends.