Understanding roles – the playbook organizer
Roles are designed to enable you to efficiently and effectively reuse Ansible code. They always follow a known structure and often will include sensible default values for variables, error handling, handlers, and so on. Taking our Apache installation example from the previous chapter, we know that this is something that we might want to do over and over again, perhaps with a different configuration file each time, and perhaps with a few other tweaks on a per-server (or per-inventory group) basis. In Ansible, the most efficient way to support the reuse of this code in this way would be to create it as a role.
The process of creating roles is in fact very simple – Ansible will (by default) look within the same directory that you are running your playbook from for a roles/
directory, and in here, you will create one subdirectory for each role. The role name is derived from the subdirectory name. There is no need to create complex...