Skip to content

Commit

Permalink
Add Saltstack
Browse files Browse the repository at this point in the history
  • Loading branch information
53845714nF committed Sep 27, 2024
1 parent 2dfddb7 commit 052b404
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 0 deletions.
Binary file added content/blog/saltstack/img/saltstack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions content/blog/saltstack/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
title: "Salt 🧂"
date: 2024-09-27T21:22:04+02:00
draft: false
hideLastModified: true
summaryImage: "img/saltstack.png"
keepImageRatio: true
summary: "A quick look at Salt, a configuration management tool."
showInMenu: false
tags: ["Saltstack", "IaC", "DevOps"]
---

Salt is a powerful tool for configuration management and automation. It allows you to manage servers by executing commands on various operating systems, including almost all common Linux distributions, the BSD family, and Windows.

Here’s a simple example of how to use Salt:
{{< codeWide >}}
salt <Minion Name> pkg.upgrade
{{< /codeWide >}}

This command upgrades all installed packages on the managed systems, regardless of whether they use `apt`, `yum`, `pacman`, or `zypper`.
In addition to running commands, you can also define custom configurations using YAML syntax to specify the desired state of a system.

To use Salt effectively, it's helpful to understand some key terms.
Salt works on a classic master-minion model.
The master acts as the central authority, holding the configurations that are stored in what are called States.
The minion is the managed system that executes the instructions from the master.

There are two basic interaction models:

- **Pull model**: The minion actively fetches commands from the master.
- **Push model**: The master sends commands to the minions.

## Salt Master

The master sets the direction and manages the instructions for the minions. By default, these configurations are stored under `/srv/salt/`. Alternatively, you can set up a Git integration, but make sure to use GitPython as the `gitfs` provider, not `pygit2`.

**Installation (Example for Debian 10)**
You can check the [Salt Repo](http://repo.saltstack.com) for how to install Salt Master on various systems.

Here’s a quick overview of how to install it on Debian 10 (as root):

1. Download and add the GPG key:
{{< codeWide >}}
wget -O - https://repo.saltstack.com/py3/debian/10/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
{{< /codeWide >}}

2. Add the SaltStack repository:
{{< codeWide >}}
deb http://repo.saltstack.com/py3/debian/10/amd64/latest buster main
{{< /codeWide >}}

3. Update the package lists:
{{< codeWide >}}
apt-get update
{{< /codeWide >}}

4. Install the Salt Master:
{{< codeWide >}}
apt-get install salt-master
{{< /codeWide >}}

## Salt Minion

The minion is the managed system where commands are executed. Its main configuration file is located at `/etc/salt/minion`, where the master server is defined.
By default, the master is set to `salt`, but this can be adjusted depending on your network environment.

**Installation (Example for Debian 10)**

As with the master, you can find installation instructions in the [Salt Repo](http://repo.saltstack.com) for various systems.

1. Download and add the GPG key:
{{< codeWide >}}
wget -O - https://repo.saltstack.com/py3/debian/10/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
{{< /codeWide >}}

2. Add the SaltStack repository:
{{< codeWide >}}
deb http://repo.saltstack.com/py3/debian/10/amd64/latest buster main
{{< /codeWide >}}

3. Update the package lists:
{{< codeWide >}}
apt-get update
{{< /codeWide >}}

4. Install the Salt Minion:
{{< codeWide >}}
apt-get install salt-minion
{{< /codeWide >}}

5. Adjust the configuration if needed.

6. Restart the service:
{{< codeWide >}}
systemctl restart salt-minion
{{< /codeWide >}}

## Salt States

Salt States are like blueprints for a system.
They describe the desired state of a machine—what programs should be installed,
what configurations should be applied, etc.
These instructions are written in YAML.
The minion fetches these "blueprints" from the master and executes them.

## Salt Grains

Grains are system properties of the minions,
such as the operating system (`os`) or the virtualization type (`virtual`).
To list all grains for a host, you can use:
{{< codeWide >}}
salt '*' grains.ls
{{< /codeWide >}}

To see the values of the grains:
{{< codeWide >}}
salt '*' grains.items
{{< /codeWide >}}

## Salt Pillar

Pillars are key-value stores primarily used for sensitive information like passwords or API keys. Unlike grains, pillars are not directly executed on the minions; they are only provided by the master.

## Conclusion 🎉

Salt provides a powerful platform for managing diverse systems.
With its push-and-pull architecture, the ability to create simple or complex configurations, and broad operating system support, it is an indispensable tool for automation in modern IT environments.

## Further Resources

- A [blog](https://thorstenkramm.gitbook.io/saltstack/) by Thorsten Kramm that eases the entry into Salt.
- The official [Salt documentation](https://docs.saltproject.io/en/latest/topics/tutorials/).
- A [talk](https://www.youtube.com/watch?v=8ytAHUGponk) about SaltStack by Thorsten Kramm (although it's quite old).

Feel free to reach out via email, LinkedIn, or GitHub if you have any comments, suggestions, or questions!
139 changes: 139 additions & 0 deletions content/blog/saltstack/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
title: "Salt 🧂"
date: 2024-09-27T21:22:04+02:00
draft: false
hideLastModified: true
summaryImage: "img/saltstack.png"
keepImageRatio: true
summary: "Ein kurzer Blick zu Salt ein Konfigurationsmanagement Tool."
showInMenu: false
tags: ["Saltstack", "IaC", "DevOps"]
---

Salt ist ein leistungsstarkes Tool für Konfigurationsmanagement und Automatisierung.
Es ermöglicht die Verwaltung von Servern durch das Ausführen von Befehlen auf verschiedenen Betriebssystemen,
darunter fast alle gängigen Linux-Distributionen, die BSD-Familie und Windows.

Ein einfaches Beispiel für die Nutzung von Salt wäre:
{{< codeWide >}}
salt <Minion Name> pkg.upgrade
{{< /codeWide >}}

Dieser Befehl aktualisiert alle installierten Pakete auf den verwalteten Systemen, unabhängig davon, ob sie mit `apt`, `yum`, `pacman` oder `zypper` arbeiten.
Neben Befehlen können auch benutzerdefinierte Konfigurationen in einer YAML-Syntax beschrieben werden, um den Zustand eines Systems festzulegen.

Um Salt effektiv nutzen zu können, ist es hilfreich, einige der wichtigsten Begriffe zu kennen.
Salt arbeitet im klassischen Master-Minion-Modell.
Der Master fungiert als zentrale Instanz, die weiß, wo es langgeht.
Er hält die Konfigurationen, die in sogenannten States abgelegt sind.
Der Minion ist das verwaltete System, das die Anweisungen des Masters ausführt.

Es gibt zwei grundlegende Interaktionsmodelle:
- **Pull-Prinzip**: Der Minion holt sich Befehle aktiv vom Master.
- **Push-Prinzip**: Der Master schickt Befehle aktiv an die Minions.

## Salt Master

Der Master gibt die Richtung vor und verwaltet die Anweisungen der Minions.Standardmäßig liegen diese Konfigurationen unter `/srv/salt/`.
Alternativ lässt sich auch eine Git-Anbindung einrichten, wobei darauf zu achten ist, GitPython als `gitfs` Provider zu verwenden, nicht `pygit2`.

**Installation (Beispiel Debian 10):**
Unter [Salt Repo](http://repo.saltstack.com) lässt einsehen, wie man Salt Master auf all den verschiedenen Systemen installiert.

Hier nur kurz gezeigt, wie das unter Debian 10 geht (als root ausführen):

1. GPG-Schlüssel herunterladen und hinzufügen:
{{< codeWide >}}
wget -O - https://repo.saltstack.com/py3/debian/10/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
{{< /codeWide >}}

2. Saltstack-Repository hinzufügen:
{{< codeWide >}}
deb http://repo.saltstack.com/py3/debian/10/amd64/latest buster main
{{< /codeWide >}}

3. Paketlisten aktualisieren:
{{< codeWide >}}
apt-get update
{{< /codeWide >}}

4. Salt Master installieren:
{{< codeWide >}}
apt-get install salt-master
{{< /codeWide >}}

## Salt Minion

Der Minion ist das verwaltete System, auf dem die Befehle ausgeführt werden. Die zentrale Konfigurationsdatei befindet sich unter `/etc/salt/minion`, wo der Master-Server festgelegt wird. Standardmäßig lautet dieser einfach `salt`, kann aber je nach Netzwerkumgebung angepasst werden.

**Installation (Beispiel Debian 10):**

Ähnlich wie beim Master lässt sich die Instalation unter [Salt Repo](http://repo.saltstack.com) einsehen.
Dieser lässt sich natürlich auf verschiedenen Systemen installieren.

1. GPG-Schlüssel herunterladen und hinzufügen:
{{< codeWide >}}
wget -O - https://repo.saltstack.com/py3/debian/10/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
{{< /codeWide >}}

2. Saltstack-Repository hinzufügen:
{{< codeWide >}}
deb http://repo.saltstack.com/py3/debian/10/amd64/latest buster main
{{< /codeWide >}}

3. Paketlisten aktualisieren:
{{< codeWide >}}
apt-get update
{{< /codeWide >}}

4. Salt Minion installieren:
{{< codeWide >}}
apt-get install salt-minion
{{< /codeWide >}}

5. Konfiguration anpassen, falls nötig.

6. Den Dienst neustarten:
{{< codeWide >}}
systemctl restart salt-minion
{{< /codeWide >}}

## Salt States

Salt States sind wie Bauanleitungen für ein System.
Sie beschreiben den gewünschten Zustand eines Rechners – welche Programme installiert sein sollen, welche Konfigurationen gelten, etc.
Diese Anweisungen werden in YAML verfasst.
Der Minion lädt diese "Bauanleitung" vom Master herunter und führt sie aus.

## Salt Grains

Grains sind systemeigene Eigenschaften der Minions, wie das Betriebssystem (`os`) oder der Virtualisierungstyp (`virtual`).
Um eine Liste aller Grains eines Hosts abzurufen, kann folgender Befehl verwendet werden:
{{< codeWide >}}
salt '*' grains.ls
{{< /codeWide >}}

Um die Werte der Grains einzusehen:
{{< codeWide >}}
salt '*' grains.items
{{< /codeWide >}}

## Salt Pillar

Pillars dienen als ein Key-Value-Speicher, der vor allem für sensible Informationen wie Passwörter oder API-Schlüssel verwendet wird.
Im Gegensatz zu Grains werden Pillars nicht direkt auf den Minions ausgeführt, sondern nur vom Master bereitgestellt.

## Fazit 🎉

Salt bietet eine mächtige Plattform für das Management unterschiedlichster Systeme. Mit seiner Push- und Pull-Architektur,
der Möglichkeit, einfache oder komplexe Konfigurationen zu erstellen,
und der breiten Betriebssystemunterstützung ist es ein unverzichtbares Tool für die Automatisierung in modernen IT-Umgebungen.

## Weitere gute Quellen

- Ein [Blog](https://thorstenkramm.gitbook.io/saltstack/) von Thorsten Kramm der den Einstieg in Salt erleichtert.
- Die offizielle [Salt Dokumentation](https://docs.saltproject.io/en/latest/topics/tutorials/).
- Ein [Vortrag](https://www.youtube.com/watch?v=8ytAHUGponk) zu Salt Stack von Thorsten Kramm. (Leider schon sehr alt.)


Falls Sie Anmerkungen, Vorschläge oder Fragen haben, können Sie sich gerne per E-Mail, LinkedIn oder GitHub bei mir melden.

0 comments on commit 052b404

Please sign in to comment.