2012-05-23 04:43:12 +00:00
|
|
|
============
|
2011-06-25 05:22:53 +00:00
|
|
|
Salt Runners
|
2012-05-23 04:43:12 +00:00
|
|
|
============
|
2011-06-25 05:22:53 +00:00
|
|
|
|
2012-10-18 22:35:15 +00:00
|
|
|
.. seealso:: :ref:`The full list of runners <all-salt.runners>`
|
|
|
|
|
2011-06-25 05:22:53 +00:00
|
|
|
Salt runners are convenience applications executed with the salt-run command.
|
2013-06-12 00:17:48 +00:00
|
|
|
Where as salt modules are sent out to minions for execution, salt runners are
|
|
|
|
executed on the salt master.
|
2011-06-25 05:22:53 +00:00
|
|
|
|
|
|
|
A Salt runner can be a simple client call, or a complex application.
|
|
|
|
|
2012-05-23 04:43:12 +00:00
|
|
|
The use for a Salt runner is to build a frontend hook for running sets of
|
|
|
|
commands via Salt or creating special formatted output.
|
2011-07-03 00:06:14 +00:00
|
|
|
|
|
|
|
Writing Salt Runners
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
Salt runners can be easily written, the work in a similar way to Salt modules
|
|
|
|
except they run on the server side.
|
|
|
|
|
2012-05-23 04:43:12 +00:00
|
|
|
A runner is a Python module that contains functions, each public function is
|
|
|
|
a runner that can be executed via the *salt-run* command.
|
2011-07-03 00:06:14 +00:00
|
|
|
|
2012-05-23 04:43:12 +00:00
|
|
|
If a Python module named test.py is created in the runners directory and
|
2011-07-03 00:06:14 +00:00
|
|
|
contains a function called ``foo`` then the function could be called with:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2012-07-27 20:13:55 +00:00
|
|
|
# salt-run test.foo
|
2011-07-03 00:06:14 +00:00
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
The best examples of runners can be found in the Salt source:
|
|
|
|
|
2011-09-25 06:36:41 +00:00
|
|
|
:blob:`salt/runners`
|
2011-07-03 00:06:14 +00:00
|
|
|
|
2012-03-15 00:09:19 +00:00
|
|
|
A simple runner that returns a well-formatted list of the minions that are
|
2012-05-23 04:43:12 +00:00
|
|
|
responding to Salt calls would look like this:
|
2011-07-03 00:06:14 +00:00
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
# Import salt modules
|
|
|
|
import salt.client
|
|
|
|
|
|
|
|
def up():
|
|
|
|
'''
|
|
|
|
Print a list of all of the minions that are up
|
|
|
|
'''
|
2013-03-09 02:23:56 +00:00
|
|
|
client = salt.client.LocalClient(__opts__['conf_file'])
|
2011-07-03 00:06:14 +00:00
|
|
|
minions = client.cmd('*', 'test.ping', timeout=1)
|
|
|
|
for minion in sorted(minions):
|
|
|
|
print minion
|
|
|
|
|