Reputation: 27139
I have a string like this as Jinja variable:
foo-VERSION-bar
I want to replace VERSION
with {{ grains.lsb_distrib_release }}
and I want this to get evaluated.
if grains.lsb_distrib_release
contains 123
I want the result to be foo-123-bar
.
How to replace and eval in jinja?
Upvotes: 0
Views: 2027
Reputation: 883
Without using replace Jinja filter, you can use its concatenation possibilities
{{ 'foo-' ~ salt['grains.get']('lsb_distrib_release') ~ '-bar' }}
Upvotes: 0
Reputation: 396
Set value of your grain to a variable:
{% set version = salt['grains.get']('lsb_distrib_release', {}) %}
Use Jinja replace function:
{{ "foo-VERSION-bar"|replace("VERSION", version) }}
Upvotes: 1