himl
himl copied to clipboard
Support for jinja syntax in yaml variables
This is a feature request
It would be really nice to be able to use a jinja template to define variables programmatically. I think jinjyaml may integrate really well with himl.
Example of jinja defined variables.
---
env: prod
deep:
key3: v3
deep_list:
- item3
jinja_array: !j2 |
{% for i in range(10) %}
- sub{{i}}: {{loop.index}}
{% endfor %}
jinja_deep_list: !j2 |
{% for i in deep_list %}
- sub-jinja-{{i}}
{% endfor %}
Produces
deep:
key1: v1
key2: v2
key3: v3
deep_list:
- item1
- item2
- item3
env: prod
jinja_array:
- sub0: 1
- sub1: 2
- sub2: 3
- sub3: 4
- sub4: 5
- sub5: 6
- sub6: 7
- sub7: 8
- sub8: 9
- sub9: 10
jinja_deep_list:
- sub-jinja-item1
- sub-jinja-item2
- sub-jinja-item3
I currently have a very alpha poc here https://github.com/adobe/himl/compare/master...chekolyn:jinjyaml_poc to produce the above example. It does introduce a new package dependency but it would open a lot of possibilities with the use of jinja syntax.
This turns himl from a yaml hierarchy merger into a full on templating engine. You can use himl as the source of the data, ex specify the start and end of that loop and inject the resulting config file in your template engine, infra code, app, etc.