guettli
guettli

Reputation: 27107

SaltStack: conditional include: Error if empty

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?

Upvotes: 2

Views: 1348

Answers (2)

pwan
pwan

Reputation: 2914

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

Upvotes: 1

guettli
guettli

Reputation: 27107

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

Upvotes: 1

Related Questions