Question

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.

Was it helpful?

Solution

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

Ordering is now sufficient.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top