What are Ansible Roles?

What are Ansible Roles ?

  • Ansible roles are set of tasks which you can perform on your target machine.

  • We can package a playbook into a role which can be used later as well.

  • Next time you just need to assign that role in a playbook like below and you can make changes to multiple targets.

  • The main purpose of role is to make your work reusable.

  • It is also used to organize your work by keeping your tasks in task directory, all variables in vars directory, all default values in defaults directory, handlers in handler directory, etc.

  • You can also share your role by others in ansible community. Ansible Galaxy is one of the communities.

 

 

 

It Organizes work

 

 

Ansible Galaxy :

To configure Role directory structure in your Controller machine. You don’t need to do that manually. You can do it by simply using ansible-galaxy tool 

 

 

$ ansible-galaxy init mysql

Above command will initialize and create a directory structure like below screenshot.

 

 

Now question is, how will your playbook know where that role is ? There are 2 methods of that :

1) Either you can create a roles directory where your playbook is and paste your role in that roles directory.

2) Or you can keep that in default location of roles at /etc/ansible/roles

 

 

To search a role : $ ansible-galaxy search mysql

 

 

To install ansible role : $ ansible-galaxy install role-name

 

Ways to specified by 2 ways :

 

What is Networking

 

Leave a Reply

Your email address will not be published. Required fields are marked *