Skip to content

Ansible Nginx

Using Nginx role with Ansible.

The role that has been tested and works is geerlingguy.nginx.

First you need to install the role so that you can use it in the playbook.

You can install the Nginx role with the following command ansible-galaxy install geerlingguy.nginx -p

You can then place it in the playbook simply by having the following:

    - geerlingguy.nginx

The role on its own without adding variables to the playbook is a quick way to get things up and running. This is what I have done however there are various changes you can make. Take a look at the github page for role variable list:

For configuration files, you can create yourself a template that can be copied across or use the role variable. I have used the template method which you can see below.

- name: Create nginx config "default.conf"
  template: src=templates/nginx/default.conf dest=//etc/nginx/conf.d/default.conf
The above takes the file "default.conf" from templates/nginx and places it on the client under /etc/nginx/conf.d.