RUNNERS
Salt runners are easy to use application salt-run command execution.
Salt runners and Salt execution module works similarly, but they need to be performed on the Salt minions in Salt master node itself, not remotely.
Salt runner can be a simple call to the customer, it can be complex applications.
You can view a complete list of runner modules to learn more knowledge runner
WRITING SALT RUNNERS
Salt runner program written in a similar manner Salt execution module. Python module comprising both functions, each function is a public through runner salt-run command execution.
For example, if you create a directory named runners test.py
Python module and contains a named foo
function, you can invoke the test runner to run with the following command:
# salt-run test.foo
Runner for selectively controlling several outputs.
Runner in any print statements will automatically trigger event to the master bus. E.g:
def a_runner(outputter=None, display_progress=False):
print('Hello world')
...
The above printing operation will trigger the following events:
Event fired at Tue Jan 13 15:26:45 2015
*************************
Tag: salt/run/20150113152644070246/print
Data:
{'_stamp': '2015-01-13T15:26:45.078707',
'data': 'hello',
'outputter': 'pprint'}
Runner can also send event schedule, the schedule event displayed to the user during execution runner, the runner and if the display_progress
parameter is set to True, the event bus may also pass through.
Custom runner can __jid_event_.fire_event()
send its own progress event method, as follows:
if display_progress:
__jid_event__.fire_event({'message': 'A progress message'}, 'progress')
Above will produce an output on the console: A progress message
, events and event messages on the bus similar to the following:
Event fired at Tue Jan 13 15:21:20 2015
*************************
Tag: salt/run/20150113152118341421/progress
Data:
{'_stamp': '2015-01-13T15:21:20.390053',
'message': "A progress message"}
Runner can use the same method to label having a self-defined event sent to the event bus, the second parameter is the method ( progress
) replaced with any desired mark. However, this will not be displayed on the command line, only to trigger the event bus.
SYNCHRONOUS VS. ASYNCHRONOUS
Asynchronously execute a runner program, which returns control immediately. In this case, if salt-run from the command line, it does not display any output to the user. If you use programmatically will not return any results. If desired result, it must then observe them or by other means to collect them from the runner by triggering events in the bus incident.
Note: When you run the program running in asynchronous mode, the
--progress
flag does not pass output to the CLI salt run. However, progress still trigger event on the bus.
In synchronous mode (default), before the runner finishes execution, control is not returned.
To add a custom runners procedures, place them in a directory and add it to the master configuration file runner_dirs .
example
Examples can be found in Salt Runer release:
https://github.com/saltstack/salt/blob/develop/salt/runners
A simple Tunner, return a formatted response list minions Salt call, as follows:
# 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'])
minions = client.cmd('*', 'test.version', timeout=1)
for minion in sorted(minions):
print minion
SALT ENGINES
New in version 2015.8.0.
Salt Engines, the external system is long-running processes, it can take advantage of on-demand Salt.
- Salt engine can access the configuration, program execution module and runners (
__opts __
,__salt__
and__runners__
). - Engine executes in a separate process from the Salt monitored. If Salt engine is stopped, it will restart automatically.
- Engine can run on Salt master and Salt minions.
Salt enhances engine and replace the external process capabilities .
Salt engine configuration
Salt in Salt master engine configuration or Salt minion configuration engines
at the top level. The following is a list of parameters and the engine part configuration example.
engines:
- logstash:
host: log.my_network.com
port: 5959
proto: tcp
Salt Salt engine must be in the path, or you can add in Salt master configuration engines_dirs
options, specify Salt try to find a directory listing Salt engines. This option should be formatted as a list of directories to search, for example:
engines_dirs:
- /home/bob/engines
WRITING AN ENGINE
Engine configuration example of a Salt, https://github.com/saltstack/salt/blob/develop/salt/engines/test.py , available from Salt source code. Develop their own customized Salt engine, the only requirement is to implement a start()
function.