Creating an Nginx role
We will now create a separate role for Nginx and move the previous code that we wrote in the simple_playbook.yml
file to it, as follows:
- Create the directory layout for the Nginx role:
$ mkdir roles/nginx $ cd roles/nginx $ mkdir tasks meta files $ cd tasks
- Create the
install.yml
file insideroles/base
. Move the Nginx-related tasks to it. It should look like this:--- - name: add official nginx repository apt_repository: repo='deb http://nginx.org/packages/ubuntu/ lucid nginx' - name: install nginx web server and ensure its at the latest version apt: name=nginx state=latest force=yes
- We will also create the
service.yml
file to manage the state of the Nginx daemon:--- - name: start nginx service service: name=nginx state=started
- We looked at the
include
directive earlier. We will use it to include both theinstall.yml
andservice.yml
files in themain.yml
file, as follows:--- # This is main tasks file for nginx role - include: install.yml - include...