ansible-galaxy init new-rolecreates a role skeleton
testrole/ ├── defaults ├── tasks │ └── main.yml │ └── main.yml ├── files ├── templates ├── handlers ├── tests │ └── main.yml │ ├── inventory ├── meta │ └── test.yml │ └── main.yml └── vars └── README.md └── main.yml
requirements.ymlfile 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
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 roles
ansible-role-rolenameto avoid clashes (you can choose what name a role gets in the requirements file
.gitignorefile (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.