Reputation: 72141
I'm trying to create the following loop in jinja:
variable: >
[
{% for replaceme in list %}
{
'name': "{{ "string-{{replaceme}}" if replaceme == 'somevalue' else "string-something-{{replaceme}}" }}",
'sshKey': "{{ lookup(...) }}"
}
{% if not loop.last %},{% endif %}
{% endfor %}
]
but this doesn't work, any ideas? i tried different quotes, different combinations of curlies, etc.
Upvotes: 9
Views: 20694
Reputation: 7945
you can use string formatting operator.
[
{% for item in list %}
{'name': {{ "s1-%s" % item }} },
{% endfor %}
]
Upvotes: 1
Reputation: 68339
Nested {{..}}
are not allowed.
Try: {{ "string-"+replaceme if replaceme == 'somevalue' else "string-something"+replaceme }}
Upvotes: 10