6

If I have to execute the following 3 commands, how do I group them so I only have to call one?

salt '*' git.fetch cwd=/var/git/myproject opts='--all' user=git
salt '*' git.pull cwd=/var/git/myproject opts='origin master'
salt '*' nginx.signal reload

I can use fabric to put those in a single function say deploy which might accept a minion name then run through master, but I'm wondering if saltstack has something built-in?

Marconi
  • 3,601
  • 4
  • 46
  • 72
  • Have you thought about creating a state where you simply run commands but have to wait for another state to finish and so on? – tudoricc Jul 10 '15 at 09:27
  • why the down vote? This is an old question, now a days I'd create a custom state file and pass as param to `state.sls` module. – Marconi Jul 10 '15 at 13:36

1 Answers1

6

This is a good candidate for a custom module.

You can read about creating custom modules here: http://docs.saltstack.com/ref/modules/index.html. Place your custom module in /srv/salt/_modules (the default location) and then run

salt \* saltutil.sync_modules

Your module will then be available to run on your minions.

If your module is named 'deploy' and the function is 'mysite', then your custom command will look like this:

salt \* deploy.mysite

If you want to target a specific minion then it will look like this:

salt 'minion_name' deploy.mysite
Utah_Dave
  • 4,531
  • 24
  • 23
  • You can actually execute these all in one run as well: salt '*' git.fetch,git.pull,nginx.signal "cwd=/var/git/myproject opts='--all' users=git","cwd=/var/git/myproject opts='origin master'","reload" – Utah_Dave May 21 '13 at 21:47