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

廉价感情. 提交于 2020-12-30 05:01:59

问题


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

回答1:


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

Try switching all your operators to lower case.



来源:https://stackoverflow.com/questions/41873717/how-to-use-logic-operators-in-jinja-template-on-salt-stack-and-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!