Ansible Role : Some Pointers

Deepak Kashyap
2 min readDec 10, 2020

Some Ansible Role Related Pointers:

1. ‘pre_tasks’ executes before roles in a playbook
2. ‘handlers’ do get executed at end of the play so beware it is not end of task file or playbook
3. ‘handlers’ are mostly used for ‘Restarting services’
4. Roles are a way of automatically loading certain vars_files, tasks, and handlers
5. Role’s task directory contains main.yml which is basically a YAML list of tasks
6. ‘tasks’ is one of the mandatory subdirectories to be present within a role directory structure
7. Default sequence for role and playbook task execution : Role tasks execute before playbook tasks
8. ‘roles_path’ has to be set in ansible.cfg to configure a specific path for Ansible to look for roles
9. Meta directory in the roles can contain Dependencies on other roles
10. If roles/rolename/vars/main.yml exists then Those variables overrule defaults/main.yml in that role
11. Defined process for creating and using a role: Create the role directory structure; define the role content; use the role in a playbook
12. Remember using role defaults is least important in terms of variable precedence
13. A role can run multiple times as a dependency if allow_duplicates is set to “true” or “yes”
14. Ansible Galaxy be used to install roles from the Ansible community to your playbook directories
15. Only if the file contains role names in the “username.rolename” format you install multiple roles from Galaxy using a file with a list of role names
16. “ansible-galaxy init newrole1 -p /etc/ansible/roles” command when executed installs a role by the name of “newrole1” at /etc/ansible/roles
17. Ansible Galaxy is a collection of community contributed roles

--

--