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
|
|
|
|
|
|
|
Salt runners are convenience applications executed with the salt-run command.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# salt '*' test.foo
|
|
|
|
|
|
|
|
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
|
|
|
|
'''
|
|
|
|
client = salt.client.LocalClient(__opts__['config'])
|
|
|
|
minions = client.cmd('*', 'test.ping', timeout=1)
|
|
|
|
for minion in sorted(minions):
|
|
|
|
print minion
|
|
|
|
|