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
Jinja can generate any text-based format (HTML, XML, CSV, LaTeX, etc.). A Jinja template doesn't need to have a specific extension: . html , . xml , or any other extension is just fine.
Instead, use the {% set %} template tag and then assign the value the same way you would in normal python code. It was great explanation and simple one.
You are doing it right but the logic operators need to be lower cased.
Try switching all your operators to lower case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With