Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make one custom state dependent on another?

Tags:

salt-stack

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?

like image 933
Jeff Bauer Avatar asked May 03 '13 15:05

Jeff Bauer


1 Answers

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).

like image 93
Daniel Watkins Avatar answered Sep 23 '22 09:09

Daniel Watkins