⚙️ Ansible

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
    - include: common/bootstrap-machine.yml
    - animal

This means that Ansible will look for features to execute at:

  1. ./roles/animal/tasks/main.yml for tasks.
  2. ./roles/animal/handlers/main.yml for handlers.
  3. ./roles/animal/vars/main.yml for variables.
  4. ./roles/animal/defaults/main.yml for variables with the lowest priority.
  5. ./roles/animal/meta/main.yml for role dependencies.

Role Dependencies

roles/animal/meta/main.yml with parametrized roles:

  - { role: common, some_parameter: 3 }
  - { role: apache, apache_port: 80 }
  - { role: postgres, dbname: blarg, other_parameter: 12 }