There are four main components that make up Ansible, tasks, roles, playbooks, and collections.

Tasks:

Tasks are individual executions of an Ansible module that operate on a defined target. They can be something as simple as copying a file from your local machine on to a remote host all the way up to installing or running applications.

Roles:

These are collections of tasks that are run together. They can be shared on Ansible galaxy.

Playbooks:

These are files that group roles and define targets that the roles should be run against.

Collections:

Collections are groups of roles and playbooks that work together. They also can be shared on Ansible galaxy.

Ansible Role Structure


Ansible roles have a predefined structure with standard folders such as:

  1. defaults: contains default variables for the role. Variables in default have the lowest priority so they are easy to override.
  2. vars: contains variables for the role. Variables in vars have higher priority than variables in defaults directory.
  3. tasks: contains the main list of steps to be executed by the role.
  4. files: contains files which we want to be copied to the remote host. We don’t need to specify a path of resources stored in this directory.
  5. templates: contains file template which supports modifications from the role. We use the Jinja2 templating language for creating templates.
  6. meta: contains metadata of role like an author, support platforms, dependencies.
  7. handlers: contains handlers which can be invoked by “notify” directives and are associated with service.