Salt: set dependency of a whole sls

Created on 15 Dec 2015  路  6Comments  路  Source: saltstack/salt

Is it possible to set a state as requirement of a sls file, so that this state is essentially required by all states in that file? I can do this with require in a puppet class, but I don't know how to do that with salt.
Thank you!

Question stale

All 6 comments

Sorry for not being clear, the document shows how to set a sls file as a requirement of a single state, I meant to set a state as a requirement of a sls file.
For example, say if I have a sls with a bunch of states in it, and I want to set all of them to depend on one state. Since currently it is not possible to use sls in a require_in statement of that state (#22852), I was wondering if there's a way to do a require in a sls file (not in every state in it).

Maybe you should look at the Salt orchestration capabilities: https://docs.saltstack.com/en/latest/topics/tutorials/states_pt5.html#orchestrate-runner

In very simple case without complex requirements between sls files, writing your main.sls like this:

include:
  - dependent

main-state:
  test.succeed_without_changes: []

will implicitly instruct Salt to run all states from dependent.sls before any state in main.sls.
This is a core concept: https://docs.saltstack.com/en/latest/ref/states/compiler_ordering.html#ordering-layers

Thank you, I'll definitely take a look.

I am facing the same issue as wenxin-wang. By default all states in an include run before the states in the file. I want the states in an include to run after a particular state in the file. So to rewrite the example:

#file: dependent.sls
dependent1:
  test.succeed_with_changes: []

dependent2:
  test.succeed_with_changes: []

and

#file: main-state.sls
include:
  - dependent

main-state:
  test.succeed_with_changes: []
    - require-in: 
      - sls:  dependent

The require-in does not currently work with sls, but if it did then the ordering for above would be

main-state
dependent1
dependent2

Which is what we are looking for.

I looked at orchestrate and that is doable, but it seems much overkill for a simple dependency on one server.

My current workaround for this is to use order: 1 on the main-state, but the require-in sls seems a better solution than having to use an order.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings