Table of contents
1.
Introduction
2.
Runners
3.
Runner Modules
4.
Write Salt Runners
5.
Synchronous vs Asynchronous
6.
Examples
7.
Frequently Asked Questions
7.1.
What is Saltstack?
7.2.
Where do we use Saltstack?
7.3.
Is Saltstack still free of cost to developers?
7.4.
What are salt runners?
7.5.
Mention some salt runners modules.
8.
Conclusions
Last Updated: Mar 27, 2024
Medium

About Salt Runners

Author Gunjan Batra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Saltstack, popularly known as salt, is a configuration management and orchestration tool. It helps in managing a large number of servers altogether. It is simple to use, fast, and can be easily manageable. 

SALTSTACK

 

This blog will discuss the salt runner's command of salt. We will explore synchronous vs asynchronous in salt. We will learn more about salt runners through different examples.

Runners

Salt Runners
  • The salt runner is a simple or can be complex application. With the help of the salt run command, you can execute the salt runners applications.
     
  • Writing salt runner is similar to writing execution modules. They are simple and easy to use. The salt runner gets executed in the salt master. The remote salt minions do not run the salt runner.
     
  • For locating the master, the value salt minions require is only the master value.

Runner Modules

Runner Modules

Various runners are available on the Saltstack. Some of them are given below:

Runners

Use

bgp BGP finder
auth For creating and managing eauth tokens, deleting authentication runners requires auth runner.
config For the master set to mirror the execution of config.py
Cache To get the cached value from minions, use cache runner.
digicertapi Support for the digicert
Event To use the runner system to send events
ddns Dynamic DNS Runner
drac To manage the Dell DRAC from the master node
doc To display the inline documents from various modules
vistra Vistra runner
error For enabling the salt runner error handling, error generator is used
virt Controlling virtual machines via salt 
winrepo To manage the windows software repo
f5 It provides the f5 load balancer functionality
thin To manage the salt thin systems, the thin salt runner is used.
Net NET Finder
Cloud Only for master settings; the runner is specially designed.
lxc Using salt-controlling Linux containers
nacl Encrypt the passwords in pillars, grain, and salt files.
jobs Manage active and already run jobs 
manage  Managing the simple salt functions like which host is up and which is down 
launchd Manage launchd silt files 
venafiapi For supporting venafi
vault Maintainer of the saltstack
mine For accessing the data from the salt mine 
http For making web calls use the http runner.
mastermost For sending messages to master most
test Not for production, only for testing purposes.
asam Novell ASAM Runner
sdb On the master for setting and querying the data, this sdb API is used.
survey When several different minions give their results, the salt runner is used to aggregate the runners. 
smartos_vmadam SmartOS minions control vmadam
state For executing orchestration funner
spacewalk Spacewalk runner 
saltutil For syncing the custom types to master, this runner command is used.
mine The data you can get from the salt mine is the mine runner.
pkg Helper functions using salt modules.pkg
salt The runner command is used to module the salt execution modules available on the master.
pillar On the master node, to interact with the pillar compiler, functions of the pillar are used.
ssh On top of the salt-ssh python API, this runner module interface is present.
pagerduty To fire the events via pagerduty. These are runner modules. 
Network  Tools that are run from the master.
queue To manage and process queue
reactor To manage the reactors, this is the convenience system.
git_pillar To manage the git external pilar, this is the direct runner module.

Write Salt Runners

Salt Runners are python modules that contain functions. These are very similar to the salt execution modules. These are the public functions, which are a runner and get executed using the salt run command. 

Write Salt Runners

For a better understanding, let's go through the following example:

In the python module, there is a module named hello.py. This contains a function func and is created in the runner's directory. The hello runner can be called with the following command:

# salt- run hello.func


To control the output, we have several other options. 

Whenever there is any print statement in the runner, it gets automatically fired on the master event bus.

def a_runner(outputter=None, display_progress=False):
    print("Coding Ninjas")
    ...


The above result in an event as follows:

Event fired at Wed Dec 07 16:46:25 2022
*************************
Tag: salt/run/20150113152644070246/print
Data:
{'_stamp': '2022-12-07T16:46:25.078707',
 'data': 'Coding',
  'outputter': 'Ninjas'}


If the display_progress to a runner is set to be true, then the runner sends the progress event to the user, which gets displayed during runner execution and gets passed across the event bus.

Using the __jid_event_.fire_event() method, the custom runner sends its progress event. The method is shown below:

if display_progress:

__jid_event__.fire_event({"message": "This is the progress message"}, "progress")


On the console, reading the above command would produce the output.  

This will show the progress message and an event similar to it. 

Event fired at Wed Dec 07 17:46:25 2022
*************************
Tag: salt/run/20150113152118341421/progress
Data:
{'_stamp': '2022-12-07T 17:46:25.390053',
'message': "This is the progress message"}


By using the same approach, the runner can send the event. If the runner wants to send an event, he can replace the second argument (progress) with the tag he wants. But this will not be shown to the command line and will only be fired on the event bus. 

Synchronous vs Asynchronous

Let us now look at how runners behave in asynchronous and synchronous modes.

Synchronous vs Asynchronous
  • When a runner has fired asynchronously, the return gets immediate. When you use the salt run from the command line, there is no output to the user. When you use this programmatically, there are no results that get returned. To get the desired results from the runner, you must either fire the events on the bus or by other means.
     
  • When you run a runner on the asynchronous mode, the progress events are still fired on the bus, but the –progress flag does not deliver the output to the salt-run CLI.
     
  • When you run in the default mode, i.e., the synchronous mode, the control is not returned until the runner finishes the execution.
     

On the master configuration file runners_dirs, you can add customs runners. 

For adding the custom_runners, first put them in the directory and then add them.

Examples

To get examples of runners, look at the salt distribution.

Below is a well-formatted look at the minions that respond to the salt calls.

# Import salt modules
import salt. client

def up():
    """
    Desc of 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)

Frequently Asked Questions

What is Saltstack?

Salt is a configuration management and remote execution tool that helps execute commands on the remote node. It is simple to use, fast and can be easily manageable. 

Where do we use Saltstack?

The Saltstack is an orchestration tool that helps change existing systems. It helps easily install the software in the IT environment and helps manage thousands of servers in a single go. 

Is Saltstack still free of cost to developers?

Saltstack is a free, open-source download and is free of cost to the programmers; however, their enterprise version costs $150 per machine per year. 

What are salt runners?

Salt Runners are python modules that contain functions. These are very similar to the salt execution modules. These are the public functions, which are a runner and get executed using the salt run command.

Mention some salt runners modules.

There are various salt runners modules. Some of them are auth, error, manage, http, pkg, salt, etc.

Conclusions

In this blog, we have learned about salt runners. We started the discussion with the introduction and then looked at the different remote salt runners, and last, we discussed the synchronous and asynchronous salt runners. 

To learn more about salt, please refer to the blogs:

About Salt Engine

Target Minions in Salt

Salt Event System

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enrol in our coursesrefer to the mock test and problems look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass