salt icon indicating copy to clipboard operation
salt copied to clipboard

Ordered states, full conditional support for `unless`/`onlyif`

Open teburd opened this issue 13 years ago • 8 comments

Its difficult to develop salt states due to the require/watch mechanisms.

I'd really like to have a "state" composed instead of ordered states.

say...

nginx:
  ordered:
     - pkg.installed
     - file.directory: 
       - name: /etc/nginx/certs
     - service.running

Another helpful addition would be the ability to simply require a whole state name as well as allow full conditionals in the require/watch/unless style clauses.

source:
   git.latest:
      .... 

deploy:
    cmd.wait:
       - name: deploy.sh
       - condition: {% state['source'] and not mydeployment_exists() %}

The two things above would take 90% of the pain away from currently developing salt states

teburd avatar Jul 11 '13 20:07 teburd

You can effectively require whole states using the overstate system: http://docs.saltstack.com/ref/states/overstate.html

Conditionals would definitely be convenient. There's an open issue for adding unless and onlyif as global state features, like require, and that will help a lot.

I think @thatch45 has been working on a simple mode where states are executed in the order defined which will help with your first one. Don't know the timeline on that feature, though.

Thanks for the requests!

basepi avatar Jul 11 '13 20:07 basepi

I don't think unless/onlyif will do it. Consider the case of a git -> build -> deploy scenario.

I really want to be able to do a series of ordered operations in this case.

  1. git
  2. build
  3. stop services
  4. deploy
  5. configure using file template
  6. start services

Right now this takes about 200 lines of sls because I don't have ordering, debugging it is a nightmare, and if something goes wrong at any step there's no easy way to correct the sls file and try again where things left off.

I hope this helps understand the problem.

If I simply had ordering like in some other config management tools this would be ridiculously simple, and problems would not cause whole situations to fail and never be run again.

teburd avatar Jul 12 '13 14:07 teburd

I think your best bet in this particular instance is to wait for @thatch45 to implement the simple ordering mechanism. Salt is very powerful in its ordering, but it does add a layer of initial complexity.

basepi avatar Jul 12 '13 16:07 basepi

@bfrog, Yeah, we're building explicit ordering right now. I'll let you know when it's finished.

UtahDave avatar Jul 12 '13 16:07 UtahDave

I'd love to see this too, in certain places I'm reverting to calling shell scripts from salt, because it results in a five-fold decrease in LOC, and no less readability/idempotence.

emilisto avatar Jul 18 '13 09:07 emilisto

I think he finished up explicit ordering. It will be in 0.17. =)

basepi avatar Jul 18 '13 18:07 basepi

I think this one's pretty much OK now :1st_place_medal:

The-Loeki avatar Apr 11 '17 21:04 The-Loeki

Oh my gosh yes

thatch45 avatar Apr 11 '17 21:04 thatch45