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:
- Create the directories required to hold templates and default variables inside a role:
$ mkdir roles/nginx/templates $ mkdir roles/nginx/defaults
- 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; index index.html; } }
- Identify the configuration parameters that you would like to generate dynamically...