Advanced templating

There are cases when you need not just input value in placeholders but also create cycles. Most DevOps specialists have experience with Ansible and its templates based on Jinja2. In such cases, you could use j2cli.

template.j2

{% for key, value in list.items()|sort() %}
***
Key: {{ key }}
Value: {{ value }}
{%- endfor %}

data.yaml

---
list:
  alpha: 1
  beta: 2

Run:

j2 template.j2 data.yaml > output.txt

Result:

***
Key: alpha
Value: 1
***
Key: beta
Value: 2

It’s just a simple example but you will be able to use all features of Jinja2 templates.