Validate your Jinja Templates with j2lint

Validate your Jinja Templates with j2lint

Jinja Tip: Validate and check your Jinja templates for syntax errors with j2lint. Ideal for integrating into a CI pipeline.

āžœ https://github.com/aristanetworks/j2lint

Here is an example below šŸ‘‡

$ uv tool install j2lint

$ cat config.j2
hostname
{%for int in interfaces%}
interface 
 ip address {{int.ip}} {{int.NetMask}}
{%endfor

$ j2lint config.j2
───────────────────────────────────────────────
JINJA2 LINT ERRORS
───────────────────────────────────────────────
config.j2
ā”œā”€ā”€ config.j2:1 A single space should be added
│   between Jinja2 curly brackets and a variable
│   name: {{ ethernet_interface }} (single-space...
ā”œā”€ā”€ config.j2:2 Jinja statement should have at
│   least a single space after '{%' and a single
│   space before '%}' (jinja-statements-single-...
ā”œā”€ā”€ config.j2:3 A single space should be added
│   between Jinja2 curly brackets and a variable
│   name: {{ ethernet_interface }} (single-space...
ā”œā”€ā”€ config.j2:4 unexpected '}' (jinja-syntax-error)
└── config.j2:4 A single space should be added
    between Jinja2 curly brackets and a variable
    name: {{ ethernet_interface }} (single-space...
Jinja2 linting finished with 5 error(s) and 0 warning(s)

Subscribe to our newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox.
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!