【问题标题】:Jinja (salt): multiple if conditionsJinja(盐):多个 if 条件
【发布时间】:2022-02-06 23:08:02
【问题描述】:

我正在寻找一种不在某些主机上执行任务的方法。我用 Jinja 尝试了不同的方法,但它不起作用。

这有效,但仅适用于一个主机:

{% if grains['id'] != 'node300.example.com' %}
  SALT TASKS
{% endif %}

我尝试了这种方法和一些变体,但没有奏效:

{% if ( (grains['id'] != 'node300.example.com') or
       (grains['id'] != 'node303.example.org') or
       (grains['id'] != 'node208.example.net') ) %}
  SALT TASKS
{% endif %}

【问题讨论】:

  • 或许你应该使用 AND 和 or OR...

标签: jinja2 salt-stack


【解决方案1】:

我收到了 IRC 的提示。这有效:

{% if grains['id'] not in ['node300.example.com',
                           'node303.example.org',
                           'node208.example.net'] %}
  SALT TASKS
{% endif %}

【讨论】:

    猜你喜欢
    • 2021-10-14
    • 2018-05-27
    • 1970-01-01
    • 2013-09-29
    • 2016-01-20
    • 2015-02-07
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多