Thursday, July 17, 2014

Run multiple commands in one salt state

Saltstack’s cmd.run is great, but what if you want to run multiple commands and you don’t want to mess with a script?


The only way I could get it to work was to have separate cmd.run blocks written in the order you want things executed. An example would be if you wanted to kill and restart a process every highstate:


Kill the process:

cmd.run:

– name: killall myproc.sh


Wait a few seconds:

cmd.run:

– name: sleep 3s


Start the process:

cmd.run:

– name: /var/lib/myproc/myproc.sh


You can have multiple commands run from one block, but these commands seem to get executed in random order:


Kill then wait then restart:

cmd.run:

– names:

– killall myproc.sh

– sleep 3s

– /var/lib/myproc/myproc.sh





No comments:

Post a Comment