-
-
Notifications
You must be signed in to change notification settings - Fork 277
Add Jinja2 templating to config #1882
I understand that the exporter config supports Jinja2 templating. I have a few use cases where this would be useful for the main config, such as conditionally adding resources/drivers, or populating a resource with a dynamic list. This can't be achieved using the !template feature.
Is there a reason that Jinja2 templating hasn't been implemented for the main config? Would you accept a PR for this?
All reactions
Replies: 1 comment 1 reply
What exactly do you want to template? Maybe an external template generation would be more suitable here?
All reactions
I would like to be able to template based on env vars, for example to create key value pairs within a resource:
Resource:
# for pair in env["LG_MAP"].split(",")
# set key, value = pair.split("=", 1)
{{ key }}: {{ value }}
# endfor
Where LG_MAP='key1=value1,key2=value2'
Or this could be used to conditionally define a resource base don an env var. For the implementation we could pass env vars prefixed with LG_ to the templating engine?
I've considered externally generating this but in our case it would be much more readable to have the templating be in the Labgrid config, otherwise there's some complicated indirection that hurts readability.