1

The Salt docs are full of this kind of pattern:

apache:
  pkg:
    - installed
  service:
    - running
    - require:
      - pkg: apache

This repetition ("install apache, now check whether apache was installed") seems to be a violation of don't-repeat-yourself (DRY). So is it necessary?

From "Understanding State Ordering":

To accomplish something similar to how classical imperative systems function all requisites can be omitted and the failhard option then set to True in the master configuration, this will stop all state runs at the first instance of a failure.

This seems to imply that the use of requisites everywhere is actually optional (assuming that the declaration order is correct) - but I'd like to know for sure.

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219

2 Answers2

3

It is a remnant of the pre 0.15 days when states weren't executed top down.

Ordering is now sufficient.

Dan Garthwaite
  • 3,436
  • 4
  • 22
  • 32
  • 1
    So is ordering respected in all these situations: formulas within a top file, statements within a formula, and functions within a statement? – Steve Bennett Feb 12 '14 at 02:52
  • You can read about it here: http://docs.saltstack.com/ref/states/ordering.html. Historically - states used to be ordered lexicographically per sls file, now they aren't. No other system had or has a surprising execution order. – Dan Garthwaite Feb 12 '14 at 04:18
  • Thanks. Weird - there are two different doc pages about state ordering (see the one I linked to). – Steve Bennett Feb 12 '14 at 05:13
  • I didn't even catch that until you pointed it out. I'll file a bug. Thanks. – Dan Garthwaite Feb 12 '14 at 16:25
1

States are now executed in the order they are declared in your sls files. Where you will still want to use "require" is if you want to ensure a certain state executes successfully before another.

For example, you may want to ensure a software package is installed correctly before attempting to lay down a config file.

apache:
  pkg:
    - installed
  file:
    - managed
    - name: /etc/apache/httpd.conf
    - source: salt://apache/httpd.conf
    - require:
      - pkg: apache

Without the "require" in the above example, the config file would be laid down even if the apache pkg failed to install.

Utah_Dave
  • 4,531
  • 24
  • 23
  • To editorialise a bit, what I find dumb about this example is why you even need the "pkg: - installed" bit. Couldn't salt just interpret "require - pkg: apache" to mean "this package has to be installed, so install it now if it's not there already". – Steve Bennett Feb 13 '14 at 04:18
  • Also, I know failhard isn't the default, but in practice for me, there's almost no point ever continuing after a failure. I need the whole box set up perfectly - failures are no good. Maybe it's useful during development. – Steve Bennett Feb 13 '14 at 04:19