Asked by: Rabab Kaletsky
asked in category: General Last Updated: 22nd May, 2020

What is the role in Ansible?

Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules. In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse.

Click to see full answer.


Similarly, it is asked, what is the use of role in Ansible?

Ansible role is an independent component which allows reuse of common configuration steps. Ansible role has to be used within playbook. Ansible role is a set of tasks to configure a host to serve a certain purpose like configuring a service. Roles are defined using YAML files with a predefined directory structure.

One may also ask, how do I create an Ansible role?

  1. Step 1 - Setup Ansible Playbook Project.
  2. Step 2 - Generate Ansible Roles for the Directory Structure.
  3. Step 3 - Setup hosts and site.
  4. Step 3 - Setup Common Roles.
  5. Step 4 - Setup 'web' Roles.
  6. Step 5 - Setup 'db' Roles.
  7. Step 6 - Run the Ansible Playbook.
  8. Step 7 - Testing.

Regarding this, what are the advantages of using Ansible roles?

Roles are designed to be reusable. Organizing playbooks with roles allows you to reuse different modules and avoid code duplication. Repetitive configuration steps, carried out into separate files, can be used many times, simply by including the required role functionality in your playbooks when necessary.

What is the difference between roles and playbook in Ansible?

Ansible playbook is a script file which contains all the tasks that need to be performed along with all the ingredients required to perform these tasks. Roles are ways of automatically certain var files, tasks, and handlers based on the known file structure.

28 Related Question Answers Found

How do you test Ansible role?

Where are Ansible playbooks stored?

What is Yaml file in Ansible?


What is Ansible galaxy?

What are modules in Ansible?

Is Ansible free?


What are handlers in Ansible?

What is Ansible medium?

What are the components of Ansible?


Is Ansible easy to learn?

Is Ansible a programming language?

What is Ansible and how it works?


What is the difference between Ansible and terraform?

What is configuration management in DevOps?