【发布时间】:2022-01-04 20:17:57
【问题描述】:
我有这段代码检查变量“所有者”是否与以下正则表达式匹配并接受它是未定义的,也就是说,剧本可以在没有传递该变量的情况下工作。
varexample is undefined or varexample is match('^[a-zA-Z]+$')
我想做的是这个变量接受空值或空值。我尝试的是这样的
varexample is null or varexample is match('^[a-zA-Z]+$')
但是我收到了这个错误:
The conditional check 'varexample is null or varexample is match('[a-zA-Z]+')' failed. The error was: template error while templating string: no test named 'null'. String: {% if varexample is null or varexample is match('[a-zA-Z]+') %} True {% else %} False {% endif %}
有人可以给我提示或帮助吗?
【问题讨论】:
-
accepts empty然后只是match('^[a-zA-Z]*$')? -
null不是 Python 中的东西(Ansible 和 Jinja 背后的语言)None是,另一方面。
标签: linux automation ansible yaml