0

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.

guettli
  • 25,042
  • 81
  • 346
  • 663

1 Answers1

1

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.

daks
  • 843
  • 2
  • 7
  • 18
  • Sorry for nitpicking, but I don't understand "'imperative' order". I understand "implicit order". But maybe I don't know enough about this. You say "sometimes I also write requisites in the same state file". Between the lines I read: most often you write one requisite per state file. Is this true? Up to now I often have roughly ten requisites per state file. – guettli Sep 05 '19 at 10:45
  • "imperative order" is the term used by salt doc. It reminds me "imperative language" (like C) vs "OO language" (like Java, Ruby) and I understands it this way. Also: in the same state file, if first step is "pkg.installed" and second is "service.running" I make the second require the first, as it has no sense without pkg installation. – daks Sep 05 '19 at 12:17
  • But "imperative order" (= from top to bottom) makes it not absolutely necesary, it's "belt and braces" type of security :) – daks Sep 05 '19 at 12:20