How to use logic operators in jinja template on salt-stack (AND, OR)

hotfire42 picture hotfire42 · Jan 26, 2017 · Viewed 37.4k times · Source

I am using a jinja template to generate a state file for salt. I added some conditionals and would like to express: if A or B. However, it seems I cannot get any logical operator working.

It doesn't like ||, |, &&(which I understand doesn't apply here), but also not and, or and not even grouping with (), which should be working according to the jinja documentation. I couldn't find any information on this in the salt docs, but I feel I must be making some stupid mistake?

My code:

{% if grains['configvar'] == 'value' OR grains['configvar'] == 'some other value' %}

Error:

Data failed to compile:
Rendering SLS 'base:mystate' failed: Jinja syntax error: expected token 'end of statement block', got 'OR'; line 3

Answer

alejdg picture alejdg · Jan 26, 2017

You are doing it right but the logic operators need to be lower cased.

Try switching all your operators to lower case.