guettli
guettli

Reputation: 27107

SaltStack: use `include:` twice in one sls file

I would like to use include: twice in a sls file:

include:
  - foo.bar

{% for system in salt['foo.get_systems'](pillar) %}
   ...
{% endfor %}

include:
  - this.is.the.end

But this fails with this message:

- Rendering SLS 'base:example.test' failed: while constructing a mapping
    in "<unicode string>", line 4, column 1
  found conflicting ID 'include'
    in "<unicode string>", line 106, column 1

I guess conflicting ID 'include' means that I can't use include: twice.

What can I do to execute something after the for-loop?

Upvotes: 0

Views: 2534

Answers (2)

Rich Bellamy
Rich Bellamy

Reputation: 21

State files are not guaranteed to be executed in a script-like order. They describe a data structure that dictates which state functions need to be run, but you should not think about them as though they are scripts, because they aren't.

You need to "include" all the SLS files that you will be including in a single include statement, and then if you need to make sure that certain states are run before or after other states, you should use the state requisite parameters like require

Upvotes: 2

guettli
guettli

Reputation: 27107

You can walk around this by working with two sls files.

Move your current sls file ("example/test.sls" which contains the for-loop) to "example/step_one.sls". Then create a new file with this content:

include:
  - example.step_one
  - this.is.the.end

Upvotes: 1

Related Questions