guettli
guettli

Reputation: 27139

SaltStack: "require: previous_state" needed?

I have a sls script which was written by a college. The next state always requires the previous state.

Example:

apache:
  service.running:
    - name: apache2
    - enable: True
    ...

apache_modules:
  apache_module.enabled:
    ...
    - require:
      - pkg: apache

server.conf:
  file.managed:
    - name: /etc/apache2/sites-available/server.conf
    ...
    - require:
      - pkg: apache

apache_sites_enabled:
  apache_site.enabled:
    - names:
      - server
    - require:
      - file: server.conf

Question: Is this "require" needed?

I guess it is not needed, since salt executes one state after the other.

I care for readabilty and would like to keep the file as small as possible.

Upvotes: 0

Views: 2118

Answers (1)

daks
daks

Reputation: 883

Normally Salt executes states in the order in which they are specified, in 'imperative' order. In the same file, it means from top to bottom.

Require/Watch/Require_in/Watch_in and others can be used to assure a specific order between some states and changes this default "linear" order. This is the 'declarative' order.

See https://docs.saltstack.com/en/latest/ref/states/ordering.html#ordering-states and https://docs.saltstack.com/en/getstarted/config/requisites.html

I tend to absolutely use requisites between independent states (like formulas) when a specific order is needed, and sometimes I also write requisites in the same state file.

Upvotes: 1

Related Questions