ansible-galaxy init new-role
creates a role skeletontestrole/
├── defaults ├── tasks
│ └── main.yml │ └── main.yml
├── files ├── templates
├── handlers ├── tests
│ └── main.yml │ ├── inventory
├── meta │ └── test.yml
│ └── main.yml └── vars
└── README.md └── main.yml
requirements.yml
file containing the specification of the role you wish to use. This can be from Ansible Galaxy or from github or your own internal source repository.The following are effectively equivalent:
- src: geerlingguy.mysql
- src: https://github.com/geerlingguy/ansible-role-mysql
version: 2.4.0
name: mysql
scm: git
The latter mechanism is more useful for roles that don't come from galaxy.
The roles are then installed using
ansible-galaxy install -p playbooks/application/env/roles \
-r playbooks/application/env/requirements.yml -f
Read the README file to see what variables are expected, and then set them appropriately in inventory.
Rather than a bunch of tasks, your playbook might then look like
- hosts: appserver
roles:
- mysql
- nginx
- application
where application
might be your role that installs your own application
ansible-galaxy init rolename
(http://docs.ansible.com/galaxy.html) command can be use to create new rolesrolename-role
or even ansible-role-rolename
to avoid clashes (you can choose what name a role gets in the requirements file.gitignore
file (or similar for your source control)There are some good reasons to version roles:
git pull upstream master
git tag v2.3
git push upstream v2.3
Using the resmo.mysql from galaxy.ansible.com, install and configure a database called catalogue:
database_name: shop
database_user: shop
database_password: sh0p
A starting playbook exists in playbooks/with_roles/install_db.yml, you'll need to install the role, and set up the inventory.