Introducing Salt

Salt is an open source project developed in Python and was created by Tomas S Hatch, back in 2011. Originally, it wasn't intended to be a configuration management tool, but rather a data collection tool and a remote command execution software that leveraged the ZeroMQ library. Later the same year, configuration management functionalities were added via states, which we will review later.

Due to the fact that Salt is written in Python, it is highly extensible and modular, and can easily write customized modules to extend its functionality even further. 

It is crucial to understand that Salt is not just a configuration management tool, but in these chapters, we will be focusing on its configuration management capabilities due to the nature of the subject at hand. In the Further reading section, I will be adding several other book recommendations if you want to learn more about other Salt functionalities.

The ways you define desired states in Salt, or in other words the languages that Salt supports, are varied. The main and default language is YAML with support for Jinja templating.

An example of a YAML definition to create a new user can be as follows:

doge:
user.present:
- fullname: much doge
- shell: /bin/bash
- home: /home/doge

YAML is a data-render language for Salt; data renders take definitions in the file and then transform them into Python data structures for Salt to consume.

The following are some other data-render languages that Salt supports:

Salt has two types of renders. The first one is the one we just talked about: data-renders. The second one is the text render, which is the category Jinja falls into. This text renders instead of returning a Python data structure, they return text instead, which is later translated for the data render.

Text renders are useful for setting up variables or loops if we need to repeat several definitions with different values but the same structure. For example, instead of creating a YAML for each user, we could create a Jinja template and create several users with the same file, as follows:

{% for user in [dsala, eflores, elilu] %}
{{ user }}:
user.present:
- home: /home/{{ user }}
- shell: /bin/bash

The preceding example will create three users instead of creating one user by file or definition. This way is more efficient because we not only save time and work by not typing the same definition over and over again, we can also easily add more users if needed in the array, without having to create an entirely new file or definition for the extra user.

Besides Jinja, Salt text-renders support other templating engines, such as the following :

We will be focusing on Jinja and YAML for the rest of the chapters.