⚙️ Ansible - Roles
Updated at 2017-03-22 01:46
Role is a collection of variables, tasks and handlers. You should always use roles with Ansible.
Ansible community maintains a huge collection of predefined roles.
# Install nginx role by jdauphant to ./roles/jdauphant.nginx
# Good quality community roles have README file with usage examples.
ansible-galaxy install jdauphant.nginx -p roles
Here we define that gorilla
hosts have animal
role.
---
- hosts: gorilla
pre_tasks:
- include: common/bootstrap-machine.yml
roles:
- animal
This means that Ansible will look for features to execute at:
./roles/animal/tasks/main.yml
for tasks../roles/animal/handlers/main.yml
for handlers../roles/animal/vars/main.yml
for variables../roles/animal/defaults/main.yml
for variables with the lowest priority../roles/animal/meta/main.yml
for role dependencies.
Role Dependencies
roles/animal/meta/main.yml
with parametrized roles:
---
dependencies:
- { role: common, some_parameter: 3 }
- { role: apache, apache_port: 80 }
- { role: postgres, dbname: blarg, other_parameter: 12 }