Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Roles provide a way of automatically loading To invoke a role in a playbook, you may use
certain var_files, tasks, and handlers based on importrole, includerole, or use the role keyword.
a known file structure.
Example:
Roles also make sharing of configuration ---
templates easier. - hosts: webservers
tasks:
- name: Include common role with variables
Roles require a particular directory structure. - include_role:
name: common
vars:
Role definitions must contain at least one of common_dist: centos
the noted directories: common_size: medium
- name: Include webserver role from non-standard path
include_role:
name: /opt/roles/webserver
in /path /to/role:
Example using two roles in a playbook using various
keywords as needed:
tasks - Contains the main list of tasks to be executed by
the role. ---
- hosts: webservers
handlers - Contains handlers, which may be used by this roles:
role or even anywhere outside this role. - common
- role: foo_app_instance
defaults - Default variables for the role (see Variables for vars:
more information). dir: '/opt/a'
vars - Other variables for the role (see Variables for more app_port: 5000
- role: foo_app_instance
information). vars:
files - Contains files which can be deployed via this role. dir: '/opt/b'
app_port: 5001
templates - Contains templates which can be deployed
via this role.
meta - Defines some meta data for this role. See below When a role is called in a playbook, Ansible looks for
for more details. the role definition in ${PWD}/roles/<role_name>