Ansible RolesΒΆ
There are two ways to use a role in your project:
- Use a predefined role found on either Ansible Galaxy or Github
- Write your own.
If you end up writing your own role, please follow these guidelines:
- Create the role template by running
ansible-galaxy init <role name>
- Put variables in
defaults/main.yml
, deletevars
(it should not be used) - Fill out
meta/main.yml
with appropriate values, and delete the others to clean up the file - When defining tasks in
tasks/main.yml
use modules whenever possible - Follow the best practices advice
For example:
Create the role:
$ cd roles
$ ansible-galaxy init foobar
$ cd foobar
$ rm -rf vars
Fill out the meta data:
$ emacs meta/main.yml
Define the tasks and variables:
$ emacs tasks/main.yml defaults/main.yml
Use the role in your playbook:
$ cd ../..
$ emacs site.yml