0Pricing
Ansible Academy · Lesson

The Role Directory Anatomy

tasks, handlers, templates, defaults, vars.

A Role Is a Folder Tree

A role is just a directory with a fixed set of subfolders. Ansible knows each folder by name and loads its contents automatically.

roles/
  nginx/
    tasks/
    handlers/
    templates/

tasks/main.yml Is the Entry Point

The tasks/main.yml file holds the role's main list of tasks. It is the first thing Ansible runs when the role is applied.

tasks/main.yml:
- name: Install nginx
  ansible.builtin.package:
    name: nginx

All lessons in this course

  1. Why Roles: From Monolith to Modules
  2. The Role Directory Anatomy
  3. Scaffold a Role with ansible-galaxy init
  4. Apply Roles & Pass Role Variables
← Back to Ansible Academy