salt/doc/ref/runners/index.rst

58 lines
1.5 KiB
ReStructuredText
Raw Normal View History

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.
2014-02-19 21:21:48 +00:00
Salt runners work similarly to Salt execution modules however they execute on the
Salt master itself instead of remote Salt minions.
2011-06-25 05:22:53 +00:00
2014-02-19 21:21:48 +00:00
A Salt runner can be a simple client call or a complex application.
2011-06-25 05:22:53 +00:00
2014-02-19 21:21:48 +00:00
.. seealso:: :ref:`The full list of runners <all-salt.runners>`
2011-07-03 00:06:14 +00:00
.. toctree::
:hidden:
all/index
2011-07-03 00:06:14 +00:00
Writing Salt Runners
--------------------
2014-02-19 21:21:48 +00:00
A Salt runner is written in a similar manner to a Salt execution module.
Both are Python modules which contain functions and each public function
is a runner which may be executed via the *salt-run* command.
2011-07-03 00:06:14 +00:00
2014-02-19 21:21:48 +00:00
For example, if a Python module named ``test.py`` is created in the runners
directory and contains a function called ``foo``, the ``test`` runner could be
invoked with the following command:
2011-07-03 00:06:14 +00:00
.. code-block:: bash
2012-07-27 20:13:55 +00:00
# salt-run test.foo
2011-07-03 00:06:14 +00:00
Examples
--------
2014-02-19 21:21:48 +00:00
Examples of runners can be found in the Salt distribution:
2011-07-03 00:06:14 +00:00
:blob:`salt/runners`
2011-07-03 00:06:14 +00:00
A simple runner that returns a well-formatted list of the minions that are
2014-02-19 21:21:48 +00:00
responding to Salt calls could 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__['conf_file'])
2011-07-03 00:06:14 +00:00
minions = client.cmd('*', 'test.ping', timeout=1)
for minion in sorted(minions):
print minion