问题
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