6

How do I make one custom state dependent on another with a requisite in an sls file?

Example: Two custom states in a _states/seuss.py module:

# seuss.py
def green_eggs():
    return {'name': 'green_eggs', 'result': True, 'comment': '', 'changes': {}}

def ham():
    return {'name': 'ham', 'result': True, 'comment': '', 'changes': {}}

I want ham to be dependent on green_eggs:

# init.sls

have_green_eggs:
  seuss.green_eggs:
  - require:
    - user: seuss

have_ham:
  seuss.ham:
  - require:
    - ???

How do I make ??? a dependency on the successful completion of green_eggs?

Jeff Bauer
  • 13,890
  • 9
  • 51
  • 73

1 Answers1

8

You would want:

have_ham:
  seuss.ham:
    - require:
      - seuss: have_green_eggs

However, you are currently defining two states of a seuss resource, which means that either a seuss.ham or a seuss.green_eggs called have_green_eggs could fulfil that requirement.

If you don't want that, then you will have to define the states in separate files (e.g. seuss_ham.exists and seuss_green_eggs.exists).

Daniel Watkins
  • 1,656
  • 1
  • 15
  • 25
  • 1
    Continuing what Daniel said, the different states in in your custom state module should be mutually exclusive. For example, for the service 'nginx' you wouldn't set up one state which was `nginx: - service.running` and one which was `nginx: - service.dead`. So too your custom state module should only contain states which would not be used simultaneously. – akoumjian May 03 '13 at 15:47