What to do if the Ansible jinja 2 if/elif/ else construct does not work?

715    Asked by ChrisDyer in Salesforce , Asked on Sep 12, 2023

 I use a jinja2 template to create various files. The differences are dependent on set variables. 

It should template the second template when the production_env is set to dev. The elif condition has stopped working. However, I used a debug task to get the output of the set variable, and it is set to dev. Ansible renders the first block if the dev is set properly. This process worked adequately before. But now it does not work. 

I have ditched the fit block and set the else. But it is not working. Any idea regarding this? 

Answered by Unnati gautam

If you are getting any issues regarding jinja, you can fix the condition by following the code:




Since the stage evaluates to true, the prod and stage make this code work fine. But the dev’s first option is always true; it does not work.



Your Answer

Interviews

Parent Categories