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:
- defaults: contains default variables for the role. Variables in default have the lowest priority so they are easy to override.
- vars: contains variables for the role. Variables in vars have higher priority than variables in defaults directory.
- tasks: contains the main list of steps to be executed by the role.
- 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.
- templates: contains file template which supports modifications from the role. We use the Jinja2 templating language for creating templates.
- meta: contains metadata of role like an author, support platforms, dependencies.
- handlers: contains handlers which can be invoked by “notify” directives and are associated with service.