Post

Jinja from the command-line without python

Jinja from the command-line without python

minijinja-cli is a CLI tool to render Jinja2 templates.

Jinja2 is very powerfull for system admins to generate config files or kubernetes descriptors. Jinja2 dependends on python and python packages. In enterprise environments it can hurt to maintain these dependencies. minijinja-cli is a rust implementation of Jinja without such dependencies.

Features

  • single command line execution
  • easy shell scripting
  • steps in CI/CD pipelines with minimal overhead and setup
  • fast template rendering as the Rust implementation is much faster than Python
  • no dependencies required / no python required

Usage

To render a file

1
2
minijinja-cli service-template.j2 service-data.yaml \
> /etc/systemd/system/my.service

or

1
2
docker run --rm -v ".:/data" stefanbudim/minijinja-cli \
/data/service-template.j2 /data/service-data.yaml  > /etc/systemd/system/my.service

This will create file my.service

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=My Custom Application Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/myapp --config /etc/myapp/config.yaml
Restart=on-failure
User=myappuser

[Install]
WantedBy=multi-user.target

Based on template and data files:

service-template.j2

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=
After=network.target

[Service]
Type=simple
ExecStart=
Restart=on-failure
User=

[Install]
WantedBy=multi-user.target

service-data.j2

1
2
3
description: My Custom Application Service
exec_start: /usr/bin/myapp --config /etc/myapp/config.yaml
user: myappuser

More examples

Generating Kubernetes YAML Files with Jinja2 Templates

Installation

Credits

Similar Tools

This post is licensed under CC BY 4.0 by the author.