Creating the www playbook
We created a site-wide playbook and used an include statement to call another playbook by the name www.yml
. We will now create this file with one play, which maps our web server hosts to the Nginx role:
--- #www.yml : playbook for web servers - hosts: www remote_user: vagrant sudo: yes roles: - nginx
The above code works as follows:
- Run this code on any host that maps to the
[www]
group specified in the hosts file. - For each directory inside the
roles/nginx/*
file, includeroles/nginx/*/main.yml
to the play. This includestasks
,handlers
,vars
,meta
,default,
and so on. This is where the auto include rules apply.
The default and custom role paths
By default, Ansible looks inside the roles/
subdirectory of the project that we create playbooks for. Being top-class devops engineers, we will follow the best practice to have a centralized, version-controlled repository to store all your roles. We may also end up reusing the roles created by community. Once we do...