Junior — Middle
How is role management and its application implemented in Ansible?
sobes.tech AI
Answer from AI
In Ansible, role management is implemented through the concept of roles — a way to structure playbooks and reuse configurations. A role contains a set of predefined directories and files, such as tasks, handlers, vars, defaults, files, templates, and meta.
Applying a role in a playbook is done through the roles key, where the role name is specified. This allows encapsulating configuration logic and simplifies maintenance and scaling of the infrastructure.
Example of using a role in a playbook:
- hosts: webservers
roles:
- common
- webserver
Here, the common and webserver roles will be applied to the webservers host group. Roles can have their own variables and tasks, which are automatically included when the role is called.