Salt Platform Instructions

The article gives an overview of the fundamental ideas behind the Salt platform, along with setup and usage examples and comments.

What is?

Built on a dynamic communication bus, Salt is an open source platform for managing infrastructure. Salt may be used to alter data, conduct commands remotely, manage settings for any collection of systems or applications, and more.

Our instructions explain how to install Salt Master and Salt Minions on running the Ubuntu 18.04 operating system, as well as how to set up their communication.

Masters и Minions

Requests to remotely execute instructions are transmitted to the Salt Master (Master), a server that serves as a command and control hub for its minions. For instance, this command displays the current disk utilization for each of the slaves under the master’s control:

salt '*' disk.usage

There are many such teams. , you can install on a minion named webserver1:

salt 'webserver1' pkg.install nginx

Salt Minions (Nodes, Minions) – these are your servers under the control of the master, it is on them that applications and services are launched. Each minion is assigned an ID, and the master can refer to this ID to assign commands to specific minions.

Communication between the master and minions is carried out using the ZeroMQ transport protocol , the channel is encrypted with a pair of public and private keys. The key pair is generated by the minion, after which it sends its public key to the master.

execution

Salt offers a very wide range of modules for remote command execution. The runtime module is a set of related functions that you can run on minions on command from the master. For example:

salt 'webserver1' npm.install gulp

In this command, npm is the module and install is the function. This command installs the Gulp Node.js package through the Node Package Manager (NPM).

The available runtime modules are convenient solutions for system administration:

  • creation and management of system users
  • installing and uninstalling software
  • editing or creating configuration

The cmd.run function is used to run arbitrary commands on managed minions:

salt '*' cmd.run 'ls -l /etc'

This command will list the contents of the /etc directory for each minion.

States, Formulas, and Top File

Salt offers another way to manage a node, which is to describe the state in which the minion should be. This kind of configuration is called Salt state (state), and the methodology is usually called configuration management.

States are defined in state files. After the minion states are described, they are applied to the minion.

Status Description

The following is an example of a state file /srv/salt/webserver_setup.sls that ensures that the following components are installed: rsync, curl, NGINX, and that NGINX is started and enabled when the OS boots:

network_utilities:
  pkg.installed:
    - pkgs:
      - rsync
      - curl

nginx_pkg:
  pkg.installed:
    - name: nginx

nginx_service:
  service.running:
    - name: nginx
    - enable: True
    - require:
      - pkg: nginx_pkg

The.sls (SaLt State) extension is used to signify state files. State descriptions, which are top-level sections and include network utilities, nginx pkg, and nginx service in the example above, can be found in one or more state files. Because description IDs are completely random, you may give them whatever name you choose.

State modules are contained in state descriptions. Although they are distinct from execution modules, state modules frequently carry out identical functions. For instance, the pkg execution module’s pkg.installed status function and pkg.install execution function may be found in the pkg status module.

State files are simply collections of dictionaries, lists, strings, and numbers that Salt then interprets. By default, Salt uses YAML syntax to represent states.

State files are usually stored on the Salt master’s file system, but they can also be stored elsewhere on the file server, such as a Git repository.

Applying State to a Minion

To apply a state to a minion, use the state.apply function on behalf of the master:

salt `webserver1` state.apply webserver_setup

This command applies the sample state webserver_setup.sls to a minion named webserver1. When applying the state, the .sls suffix is ​​not mentioned. All state descriptions from the state file are applied.

Formulas

Formulas are only collections of states that when combined, configure a system or application component on a minion. Formulas are often laid down in a variety of ways. files sls. It may be simpler to manage your work if you separate formula states into various files. Declarations in other files may be referred to and included in state declarations.

Top file

In addition to manually applying states to minions, Salt provides the ability to automatically display which states should be applied to different minions. This is called the top file.

A simple example of the /srv/salt/top.sls file:

base:
  '*':
    - universal_setup

  'webserver1':
    - webserver_setup

base is the environment. You can specify more than one environment corresponding to different phases of your work; for example: development, QA, production.

The example above says that the universal_setup state should apply to all minions (‘*’), while the webserver_setup state should only apply to the webserver1 minion.

If you run the state.apply function with no arguments, Salt will check the top file and apply all the states in it according to the generated mapping:

salt '*' state.apply

Storage of Data (data) and Secrets (secrets)

A Pillar function in the Salt framework distributes specific data from the master to the minions. Pillar is mostly used to store sensitive information like credentials. If you don’t want to write non-secret information directly to state files, Pillar is a useful location to keep it.

Let’s imagine you want to give each of your minions a unique skin by creating system users for them. This data might be encoded into a state file, but it would necessitate a new declaration for every user. You just need to build one state declaration and add the data to it if you store the data in Pillar instead.

Such data is stored in .sls files, such as the /srv/pillar/user_info.sls file:

users:
  joe:
    : /bin/zsh
  amy:
    shell: /bin/bash
  sam
    shell: /bin/fish

As with state files, the Top file (separate from the Yop state file) maps Pillar data to minions, like /srv/pillar/top.sls:

base:
  'webserver1':
    - user_info

The template is Jinja

To use Pillar data in state files, Jinja templates are used .

The following is an example of a /srv/salt/user_setup.sls state file that uses the Pillar data from the previous section to create system users and set up a shell:

{% for user_name, user_info in pillar['users'].iteritems() %} {{ user_name }}: user.present: - shell: {{ user_info['shell'] }} {% endfor %}

Salt will compile the state file into a similar file before applying it to the minion:

joe:
  user.present:
    - shell: /bin/zsh
amy:
  user.present:
    - shell: /bin/bash
sam:
  user.present:
    - shell: /bin/fish

In the following example, the state file /srv/salt/webserver_setup.sls will install and set the name for the package to match the operating system:

install_apache:
  pkg.installed:
    {% if grains['os'] == 'CentOS' %}
    - name: httpd
    {% else %}
    - name: apache
    {% endif %}

More information can be found in the official product documentation .

 

Welcome to the world of DomainRooster, where roosters (and hens) rule the roost! We're a one-stop shop for all your entrepreneurial needs, bringing together domain names and website hosting, and all the tools you need to bring your ideas to life. With our help, you'll soar to new heights and hatch great success. Think of as your trusty sidekick, always there to lend a wing and help you navigate the sometimes-complex world of domain names and hosting. Our team of roosters are experts in their fields and are always on hand to answer any questions and provide guidance. So why wait? Sign up today and join the ranks of the world's greatest entrepreneurs. With DomainRooster, the sky's the limit! And remember, as the saying goes, "Successful people do what unsuccessful people are not willing to do." So don't be afraid to take that leap of faith - DomainRooster is here to help you reach for the stars. Caw on!