Ansible jinja2 if/elif/else construct not working anymore
-
I am using a jinja2 template for creating several files. Those differ a bit dependent on a set variable.
Here's the code:
{% if production_env == "prod" or "stage" %} password: "{{ group_token }}" username: usernamedoesntmatterhere {% elif production_env == "dev" %} password: "{{ mytoken }}" username: "{{ mytokenname }}" {% else %} NONE {% endif %}
As you can see when
production_env
is set todev
it should template the second block. It seems that my elif condition is not working anymore. I used a debug task to get output which variable is set and this is correctly set todev
Ansible renders the first block even ifdev
is set correctly.That worked fine for months, not sure why it doesn't now.
I already ditched the
elif
block and set it toelse
, even this is not working.Any hints?
Thanks
-
Fix the condition
{% if production_env == "prod" or production_env == "stage" %} password: "{{ group_token }}" username: usernamedoesntmatterhere {% elif production_env == "dev" %} password: "{{ mytoken }}" username: "{{ mytokenname }}" {% else %} NONE {% endif %}