Sobes.tech
Junior — Middle

Explain what a role list in Ansible is and how it is used to organize automation.

sobes.tech AI

Answer from AI

In Ansible, a list of roles is a way to structure and organize automation by breaking tasks into independent, reusable modules (roles). A role contains a set of playbooks, tasks, variables, files, and templates necessary for configuring a specific component or function.

Using roles allows:

  • Improving code readability and maintainability.
  • Easily reusing and sharing configurations.
  • Dividing responsibilities among teams.

Example of a role structure:

roles/
  webserver/
    tasks/
      main.yml
    handlers/
      main.yml
    templates/
      nginx.conf.j2
    vars/
      main.yml

In a playbook, a role is included as follows:

- hosts: servers
  roles:
    - webserver

This simplifies managing complex infrastructures and speeds up the automation process.