Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for jinja syntax in yaml variables #100

Open
chekolyn opened this issue Jun 22, 2022 · 1 comment
Open

Support for jinja syntax in yaml variables #100

chekolyn opened this issue Jun 22, 2022 · 1 comment

Comments

@chekolyn
Copy link

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 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.

@danielcoman
Copy link
Contributor

danielcoman commented Sep 30, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants