The Ansible roles They are a tool that is responsible for the managing the configuration of an administration task group on different web servers and they are easily assignable to groups of hosts. Furthermore, it is the main method for dividing a playbook in multiple files, making it easy to reuse.
It works as an equivalent to a library, because it is a series of common tasks in a role, which can then be reused by many others playbooks.
Ansible Role Features
The roles or ansible roles are characterized by be limited to a specific functionality or a certain result, which includes the necessary steps to obtain it, either within that same role or other ansible roles called dependencies.
Although this tool can be run independently, There is no direct way to put it into operation, but can only be put into practice within a Ansible playbook. In addition to this, it does not have a detailed configuration for the host in which it will be applied.
Another of its characteristics is that are defined by YAML data serialization format files with a predefined directory structure.
Ansible roles (ansible roles) They have a structured file system design and have a folder architecture, containing a file of type main.yml with the most relevant content of each classification and that allows the inclusion of files other than the main file. Some of these folders ansible roles are:
Default: contains variables that are default for the role, so they are easier to override and have a low priority level. It is represented by the file roles/x/defaults/main.yml, where Ansible fulfills the function of adding variables so that they are reproduced.
Vars– Include variables for Ansible roles and have a higher priority over variables located in the default directory. They identify with the file roles/x/vars/main.yml.
Tasks– Refers to the main list of steps that will be executed by a specific role. Includes the file roles/x/tasks/main.ymlwhere Ansible can add tasks to the play.
Files: includes the files that the user wants to copy to the host remote. For this directory, a stored resource path does not need to be specified. Includes the file roles/x/{files,templates,tasks}/.
Handlers: refers to the tasks that will be executed after being notified in another task reporting a change.
Templates– Refers to the file template that allows modifications to Ansible roles.
Goal: contains the metadata of the role, such as the author, dependencies, and supporting platforms. When the file exists roles/x/meta/main.ymlAnsible is responsible for adding the dependencies to the role list.
Uses of Ansible roles
This tool It is used to configure a large number of serversusing only one controller request, such as ansible playbook roles. Furthermore, also helps in automating tasks such as loading variables, files, controllers, tasks and other elements of Ansible Automation Platform, as well as the implementation of applications or creation of CI/CD pipelines, among others. Ansible roles too provide a framework for collections of variablestemplates or modules of independent or interdependent type.
In addition, the configuration of this tool makes it easy to reuse easily and even share it with the community, so the user has the possibility of applying the roles created by someone else in their infrastructure.
Ansible roles can be used in three different ways:
At the level of playbook: EITHER ansible playbook roles is the traditional way of using roles and is executed through the option roles .
At the level of tasks dynamically: allows to reuse roles dynamically in any part of the tasks through the command include_role.
At the level of tasks statically: The ansible tasks facilitate the reuse of roles statically in any part of a task thanks to the command import_role.
Another of the commands that can be used in Ansible roles, apart from the ansible tasks roles and the rest are:
-ho –help: displays the help message. –vo –verbose: It is the detailed mode, and includes: –vvv: to see more.
-vvvv: enables connection debugging.
-version: shows the version number used by the program.
Ansible Galaxy
Ansible Galaxy is the main repository where Ansible roles are available that the user can place directly in its playbook to improve your automation processes. Additionally, this tool classifies a large number of roles developed by the Ansible community into the database, networkingsecurity, web system, cloud, packages ansible-playbook role networks, development and monitoring.
What is the next step?
Now that you know what roles are in Ansible and their most important characteristics and uses, such as ansible playbook roles either ansible taskstake the next step and continue your training process about this and other tools through our DevOps & Cloud Computing Full Stack Bootcamp, where in less than 6 months you can learn everything you need to become an expert in this and other elements of Ansible, which will allow you to gain an advantage over your competitors in the technology sector. In addition, you will be able to train in methodologies that will allow you improve and streamline your technological development processes.