Catalog / SaltStack Cheat Sheet
SaltStack Cheat Sheet
A quick reference guide to SaltStack, covering essential commands, configurations, and concepts for efficient task automation and system management.
Core Concepts & Architecture
Key Components
Salt Master |
Central control node that issues commands and manages configurations. |
Salt Minion |
Agent installed on managed nodes that executes commands received from the Salt Master. |
Salt States |
Declarative configurations written in YAML that define the desired state of a system. |
Salt Modules |
Python modules that provide functions for managing system resources and services. |
Salt Grains |
System properties discovered by the Minion and reported to the Master (e.g., OS, architecture). |
Salt Pillars |
Secure data store for sensitive information (e.g., passwords, API keys) that can be used in States and Modules. |
Communication Flow
|
Configuration Files
Master Configuration: |
|
Minion Configuration: |
|
Pillar Data: |
|
State Files: |
|
Common Salt Commands
Basic Commands
|
Check the connectivity to all minions. |
|
Check the connectivity to a specific minion. |
|
Apply all states to all minions. |
|
Apply all states to a specific minion. |
|
Execute a shell command on all minions. |
|
Execute a shell command on a specific minion. |
Targeting Minions
|
Target all minions using regular expression. |
|
Target minions with the ‘os’ grain equal to ‘Ubuntu’. |
|
Target minions with the ‘role’ grain equal to ‘webserver’. |
|
Target a list of minions. |
|
Target minions using compound matching. |
State Management
|
Apply all states defined in the top file. |
|
Apply a specific state to a minion. |
|
Show the compiled highstate for all minions. |
|
Show the compiled state for a specific SLS file. |
|
Dry run, show changes without applying them. |
Salt States and SLS Files
Basic SLS Structure
SLS (Salt State) files are written in YAML and define the desired state of a system.
|
Common State Modules
|
Install a package. |
|
Remove a package. |
|
Ensure a service is running. |
|
Ensure a service is stopped. |
|
Manage a file’s content. |
|
Ensure a file is absent. |
|
Create a user. |
|
Remove a user. |
State Requisites
|
Ensures a state is executed before the current state. |
|
Ensures the current state is executed before another state. |
|
Executes a state when another state changes. |
|
Another state executes when the current state changes. |
|
Includes another state as if its declarations were part of the current state. |
Pillars and Grains
Pillar Data
Pillars are used to define sensitive data that should be available only to certain minions.
|
Accessing Pillar Data
In States: |
|
In Jinja Templates: |
|
From the Command Line: |
|
Grains
Grains are system properties that are automatically discovered by the Minion and made available to the Master. Examples: |
Accessing Grains
In States: |
|
In Jinja Templates: |
|
From the Command Line: |
|