Table of contents
1.
Introduction
2.
Storing Job Results
2.1.
Default Job Cache
2.1.1.
Increase the Storage Period
2.1.2.
Disable Job Cache
2.2.
External Job Cache (Minion Side Returner)
2.2.1.
👍 Advantages
2.2.2.
👎 Disadvantages
2.3.
Master Job Cache (Master Side Returner)
2.3.1.
👍 Advantages 
2.3.2.
👎 Disadvantages
3.
Salt Returners
4.
Configure Salt for External and Master Job Cache
4.1.
For External Job Cache
4.2.
For Master Job Cache
5.
Frequently Asked Questions
5.1.
What is a Salt Master?
5.2.
What is a Minion?
5.3.
Which companies use SaltStack?
6.
Conclusion
Last Updated: Mar 27, 2024
Medium

Job Results in Salt

Author Neha Chauhan
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Salt or SaltStack is an infrastructure management tool for managing hundreds of Computer Systems by using high-speed communication. It is built using Python. It uses a simple and human-readable language YAML; hence programming knowledge is not required to use Salt.

You can automate the deployment and configure complex IT systems by using Salt. 

Salt works on the master-slave model. Using the Master, you can send commands and perform system configuration of the Slave systems. The Slaves are called Minions in Salt/SaltStack. 

job results in salt

In this article, we will discuss how to store the Job results in Salt. 

Storing Job Results

After performing some tasks, Salt stores the results obtained in a storage called the Default Job Cache

Default Job Cache

When the results are returned from the Salt Minion to the Salt Master, it is stored in temporary storage called the Default Job Cache in which the results are stored for a period of 24(twenty-four) hours. The data will be stored in the local storage of the Salt Master. 

Increase the Storage Period

The default duration for storing the data can be adjusted by configuring the keep-jobs parameter of the Salt Master configuration file. The value passed to this parameter is in hours. 

Usage: 

keep-jobs: 36

 

The above configuration will store the data for 36 hours. 

Disable Job Cache

You can also disable the job cache for some jobs. To disable the job cache, set the job-cache parameter to False in the salt master configuration files. 

Usage:

job-cache: False

 

The above configuration will disable the caching of job results obtained from the minions. 

As we mentioned before, the data is stored in the local storage of the Salt Master. 

Salt provides two mechanisms for storing the cache data in external databases (like, SQL, Redis, Syslog) instead of the local storage of the Salt Master - the First is by using the External Job Cache and the Second is by using the Master Job Cache

The difference between these two methods is - who is returning the data? The Salt Master or the Salt Minion?

External Job Cache (Minion Side Returner)

After performing a job, the Salt Minions send the results to the Salt Master. 

When this configuration is used, the results generated by the Salt Minions will be sent to the Salt Master as well as to the External Cache (like SQL, Redis, Syslog). The job of sending the data from the Minions to the External Cache is done by the Salt Runner module running on the Salt Minions.

👍 Advantages

The advantage of this configuration is that NO additional load is put on the Salt Master since the data is being sent to the External Storage by the Salt Minion itself. 

👎 Disadvantages

Since the Salt Minions have to send the results to the Salt Master as well as the External Database, the load on the Salt Minion increases by a large amount. The number of connections also increases and maintaining so many connections is quite difficult. 

Master Job Cache (Master Side Returner)

In this type of Configuration, the results are first sent from the Salt Minion to the Salt Master and then they are sent to the External Cache by the Salt Master, unlike the External Job cache configuration, in which the Salt Minion sent the results to the Salt Master as well as the External Cache. 

👍 Advantages 

Since data is being sent to the Salt Master and then to the External Cache, only one connection will be used (since there is only one master, only one connection between the Salt Master and the External Cache is needed.)

👎 Disadvantages

The load on the Salt Master increases. 

Now that we have discussed, the differences between the two configurations for sending data to the External Cache, let’s discuss how to configure the External and Master Job Cache. 

Salt Returners

Before we discuss how to configure External and Master Job Cache, let’s discuss Salt Returners. 

Salt Returners help redirect the data to external stores. It performs any necessary operation on the data before sending it to the external cache. 

In Salt, after a job is performed the result is sent to the Salt Master until we specify a returner. A Returner will send the data to the specified External Cache and ALSO to the Salt Master. 

There are built-in returners for many different types of External Caches. Some of them are - jango_return, mysql, odbc, telegram_return, slack_returner, etc. 

Syntax of using a Returner

salt '*' <test.version> --return <returner1_name, returner2_name……, returnerN_name>

Configure Salt for External and Master Job Cache

After making the required configurations in the External Storage System, make the configurations in Salt to send the data to the External Storage System. 

You need to configure the External Cache to accept data from SaltStack. 

For Example, MySql should have the following configurations:

  • A database is created using the schema that is required by the MySql returner (the inbuilt returner).
     
  • A user that has access to the database.
     
  • Optional SSL configuration.
     

The configuration file will look like this: 

mysql.host: 'salt'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306

 

These returner configurations for the External Job Cache should be added to the Minion Configuration files, and for the Master Job Cache, they should be added to the Master Configuration files. 

For External Job Cache

For External Job Cache the Returner configurations can be declared in any one of these:

  • Salt Minion Configuration file.
     
  • Minion’s Grain.
     
  • Minion’s Pillar Data.
     

NOTE: While using External Job Cache, the returner settings are added to the Minion Configuration file, but the External Job Cache setting is configured in the Master Configuration file. 

The configuration to enable the External Job Cache is given below:

ext_job_cache: <returner_name> 

 

If you are using MySql as the External Job Cache, the configuration will be as follows: 

ext_job_cache: mysql

For Master Job Cache

Fo Master Job Cache, the Returner Configurations should be declared in the Salt Master’s configuration file. 

The configuration to enable the Master Job Cache is given below: 

master_job_cache: <returner_name> 

 

If you are using MySql as the Master Job Cache, the configuration will be as follows:

master_job_cache: mysql

 

NOTE: After adding the configurations restart the Salt Master Service. 

Frequently Asked Questions

What is a Salt Master?

The core idea of Salt is that of a Master who commands one or more Minions. The Master is the Central Management System. Executed on managed systems, the Salt minion communicates with Salt Master via instructions and configurations. Linux is the default operating system for the Salt Master, although any other system can be a minion.

What is a Minion?

Your servers, which power your apps and services, are called salt minions. These are the managed systems that respond to commands from Salt Master. The Salt master can target commands to particular minions by using the ID that has been assigned to each minion.

Which companies use SaltStack?

Various organizations use SaltStack software to manage and protect digital business infrastructure at scale, including TD Bank, IBM Cloud, LinkedIn, eBay, Lego, First Data, Adobe, Bloomberg, Sanofi, and thousands more.

Conclusion

Pat yourself on the back for finishing this article. In this article, we discussed the different ways of storing the results obtained from performing some jobs by the Salt Minion. We discussed the default storage methods and the methods to store the data in External Caches. 

Do not stop learning! We recommend you read these articles - 

🔥 Job Cache in Salt

🔥 Introduction to Salt

🔥 About Salt 

Head to the Guided Path on the Coding Ninjas Studio and upskill in Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more courses.

If you want to Practice top Coding Problems, attempt mock tests, or read interview experiences, head to the Coding Ninjas Studio, our practice platform.

We wish you Good Luck!🎈 Please upvote our blog 🏆 and help other ninjas grow.

Live masterclass