Following, we show how to use the different data file formats supported
bu j2cli to render an nginx configuration file template, nginx.j2
:
server {
listen 80;
server_name {{ nginx.hostname }};
root {{ nginx.webroot }};
index index.htm;
}
Data file contents:
{
"nginx":{
"hostname": "localhost",
"webroot": "/var/www/project",
"logs": "/var/log/nginx/"
}
}
Usage:
$ j2 config.j2 data.json -o config
$ j2 -f json config.j2 - < data.json > config
Data file contents:
nginx:
hostname: localhost
webroot: /var/www/project
logs: /var/log/nginx
Usage:
$ j2 config.j2 data.yaml -o config
$ j2 -f yaml config.j2 - < data.yaml > config
Data file contents:
[nginx]
hostname=localhost
webroot=/var/www/project
logs=/var/log/nginx/
Usage:
$ j2 config.j2 data.ini -o config
$ j2 -f ini config.j2 - < data.ini > config
Data file contents:
NGINX_HOSTNAME=localhost
NGINX_WEBROOT=/var/www/project
NGINX_LOGS=/var/log/nginx/
Usage:
$ j2 config.j2 data.env -o config
$ j2 -f env config.j2 - < data.env > config
Render directly from the current environment variable values:
Usage:
$ export NGINX_HOSTNAME=localhost NGINX_WEBROOT=/var/www/project NGINX_LOGS=/var/log/nginx/
$ env | j2 -f env config.j2 - > config