SaltStack: conditional include: Error if empty

江枫思渺然 提交于 2021-02-04 21:01:50

问题


I have a conditional include which looks like this:

include:
{% if CONDITION-A %}
  - foo.bar
{% endif %}
{% if CONDITION-B %}
  - blu.bla
{% endif %}

This works in most cases.

But it fails if CONDITION-A and CONDITION-B are false.

How to handle this?


回答1:


I use this pattern now:

include:
  - dummy
{% if CONDITION-A %}
  - foo.bar
{% endif %}
{% if CONDITION-B %}
  - blu.bla
{% endif %}

dummy.sls:

dummy-no-op:
  test.nop

Not nice, but works.

Better (simpler, more obvious) answers are welcome.

Docs for test.nop




回答2:


This is also ugly, but you could wrap the entire include block in an if condtion that check if either CONDITION-A or CONDITION-B is true:

{% if CONDITION-A or CONDITION-B %}
include:
  {% if CONDITION-A %}
  - foo.bar
  {% endif %}
  {% if CONDITION-B %}
  - blu.bla
  {% endif %}
{% endif %}

This way jinja will remove the include block if both conditions are false



来源:https://stackoverflow.com/questions/56668691/saltstack-conditional-include-error-if-empty

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