Templating the Nginx configurations

You have learnt a lot about facts, variables, and templates. Now, lets transform our Nginx role to be data driven. We will start templating the default.conf file for Nginx that we created earlier. The approach toward converting a file into a template would be as follows:

  1. Create the directories required to hold templates and default variables inside a role:
    $ mkdir roles/nginx/templates
    $ mkdir roles/nginx/defaults
    
  2. Always start with the actual configuration file, our end result of this process, to know all of the parameters it would take. Then, work backwards. For example, the configuration for the default.conf file on our system is as follows:
     server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; ...

Get Ansible Playbook Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.