How to establish requisite ordering relationships between salt state files(.sls)?

Viewed 38

I have been working on puppet to salt migration of nginx module with manifest files: init.pp, package.pp, conf.pp and service.pp. The init.pp file contains below lines:

init.pp:

class nginx {
  class {'nginx::package': } ->
  class {'nginx::conf': } ->
  class {'nginx::service': }
}

I was able to implement order of execution with -> between manifest files.

So for salt, I tried the below to implement order of execution for .sls files as shown below but didn't work during run time.

init.sls:

include:
  - package.sls
  - conf.sls
  - service.sls

In case of salt I know it allows ordering/relationships between states, but can someone suggest me on how to implement order of execution between salt state files (package.sls, conf.sls and service.sls) ?

1 Answers

There is no way to define an ordering between files, but there is a way to make a state depend on an entire file:

mystate:
  test.nop:
    - require:
      - sls: package

https://docs.saltproject.io/en/latest/ref/states/requisites.html#require-sls-file

If service.sls depends on states in conf.sls then those relationships should be defined in those two files. They cannot sensibly be defined in a separate file.

Even better would be to only add dependencies between the specific states that need them, rather than every state in a file. An example service.sls:

include:
  - package.sls
  - conf.sls

nginx:
  service.running:
    - enabled: true
    - reload: true
    - require:
      - pkg: nginx
    - watch:
      - file: /etc/nginx/*

Or in this particular case, just don't split them up.

Related