I am trying to iterate through a list using jinja2 template. I have the following variables defined
vars:
app_name: testapp
testapp_env_vars:
- name: environment
value: prod
- name: type
value: api
I want to check the following
1) Whether the list "test_app_env_vars" is defined
2) if defined, then iterate through the key-value pair in the list using FOR loop and print the following
environment: prod
type: api
I tried using the following template, but its failing
{% if {{ app_name }}_env_vars is defined %}
{% for item in {{ app_name }}_env_vars %}
{{ item.name }}: {{ item.value }}
{% endfor %}
{% endif %}
where "app_name" = "testapp" which is already defined in the vars
section.
Any idea why { app_name }}_env_vars
inside IF
condition is not evaluating to testapp_env_vars
?