How to Create a Role in Ansible Galaxy

The Ansible tool’s function is to keep pushing the code to the production servers without manual intervention – Ansible automates it. In this post, you will know how to create a Role in Galaxy.

Deployment, in the traditional approach, is tedious. When you use deployment orchestrators, they will take care of password management, monitoring, and deployment.

Deployment Orchestrators and rules to create a Role:

  1. List of Deployment Orchestrators
  2. Roles in Ansible Orchestrator

1. Top Deployment Orchestrators.

PuppetBroad community support
 Some coding skills recommended
 Extensible using Ruby
 Requires agents installed on all clients
ChefIntegrated with Git
 Some coding skills recommended
 Extensible using Ruby
 High learning curve
 Broad community support
 Requires chef-client installed on all clients
AnsibleSysadmin friendly
 Python-based
 No code needed, no host-based agents
 Simple, fast connections work via SSH
 Run via text-based files (called playbooks)
 Minimal learning curve
SaltWorks through agents (called minions)
 Highly scalable
 Sysadmin friendly
List of Top Deployment Orchestrators.

2. Roles in Ansible Orchestrator.

In Ansible, Playbooks play superior role. A play book is a big file, that contain all the infrastructure needed, to run in Ansible.

Playbooks.

Playbooks and roles are similar. Different at the same time. A playbook is a standalone file that Ansible can run that contains all of the information required to set a machine’s state to what you expect.

A playbook can contain variables, tasks, handlers, roles, and even other playbooks, all in the same file. You don’t need any other files to accomplish your task.

So, the playbook is a Master file, which is executable. The role file, you cannot execute on its own.


One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Roles.

You can think of a role as a playbook that splits up into multiple different files. Instead of having a single file that contains everything that you need, there’s one file for variables, one for tasks, and another for handlers.

You can’t run a role on its own, though; you need to include it inside a playbook along with the information about which hosts to run on.

When installing a role, you can either install it globally on your machine or locally to a project. As with any dependency, you want it to be local to your project in case multiple projects need different versions of the same dependency.

Ansible roles are premium parts of Ansible. They help keep your playbooks clean and readable.

You can store the roles you created in https://galaxy.ansible.com/ , which is a public directory.

Rules to Create a Role.

  • When creating a role, try to make sure that it is usable out of the box. If your role installs a specific piece of software, make it install and configure a basic installation without any user intervention.
  • Two types of roles present – Opinionated and un-opinionated. In the public galaxy, you will find Un-opinionated roles -means general use. The Opinionated roles – pertains to a certain app or clients. Checkout here steps to create a Role.

Keep Reading

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.