问题描述
我正在使用一个Jinja模板来生成盐的状态文件.我添加了一些条件,并希望表达:if A or B
.但是,看来我无法让任何逻辑运算符正常工作.
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.
它不喜欢||, |, &&
(据我所知不适用于此处),但也不喜欢and, or
,甚至不与()
分组,后者应根据 jinja文档.我在salt文档中找不到与此有关的任何信息,但是我觉得我一定在犯一些愚蠢的错误?
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?
我的代码:
{% if grains['configvar'] == 'value' OR grains['configvar'] == 'some other value' %}
错误:
Data failed to compile:
Rendering SLS 'base:mystate' failed: Jinja syntax error: expected token 'end of statement block', got 'OR'; line 3
推荐答案
您做对了,但是逻辑运算符需要为小写.
You are doing it right but the logic operators need to be lower cased.
尝试将所有运算符切换为小写.
Try switching all your operators to lower case.
这篇关于如何在盐堆栈上的Jinja模板中使用逻辑运算符(AND,OR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!