LinuxCommandLibrary

salt

Manage and automate server infrastructure

TLDR

List connected minions

$ salt '*' test.ping
copy

Execute a highstate on all connected minions
$ salt '*' state.highstate
copy

Upgrade packages using the OS package manager (apt, yum, brew) on a subset of minions
$ salt '*.example.com' pkg.upgrade
copy

Execute an arbitrary command on a particular minion
$ salt '[minion_id]' cmd.run "ls "
copy

SYNOPSIS

salt <target> <function> [arguments] [options]

Examples:
salt '*' test.ping
salt 'webservers' state.apply apache
salt -G 'os:Ubuntu' cmd.run 'ls -l /etc/'

PARAMETERS

-t, --target-type
    Defines how the target expression is interpreted (e.g., glob, grain, list, pcre, compound).

-L, --list
    Target a list of minions provided as a comma-separated string.

-G, --grain
    Target minions based on specific grain values (e.g., os:Ubuntu).

-C, --compound
    Target minions using a compound match expression, combining different target types.

-E, --pcre
    Target minions using PCRE (Perl Compatible Regular Expression) on their IDs.

-a, --arg
    Pass positional arguments to the execution module function.

--timeout
    Set the maximum execution time in seconds for the command (default 5 seconds).

-J, --json
    Output the results in JSON format.

-v, --verbose
    Increase the verbosity of the output.

--state-output
    Specifies the format for state module output (e.g., full, changes, terse, mixed).

--async
    Execute the command asynchronously, returning a job ID immediately and running in the background.

--out, --output
    Specify the output formatter for the results (e.g., json, yaml, raw, highstate).

--log-level
    Set the level of logging messages to display (e.g., debug, info, warning, error).

DESCRIPTION

salt is the primary command-line interface for SaltStack, an open-source, Python-based automation and configuration management system.

It allows users to issue commands to Salt minions (managed servers) from a Salt master. The command supports various targeting mechanisms to select specific minions or groups of minions. Key functionalities include remote execution (running arbitrary commands or modules), state management (applying desired configurations defined in Salt states), and orchestration (coordinating actions across multiple systems).

salt leverages a fast, secure, and bidirectional communication layer for efficient operations at scale. It's widely used for server provisioning, software deployment, system maintenance, and infrastructure automation in data centers and cloud environments.

CAVEATS

Using the salt command requires a running Salt master and minions connected to it, with their keys accepted.

Proper firewall configuration is necessary to allow communication between master and minions (default ports: 4505 and 4506 for master, 4506 for minion communication).

Incorrect targeting or function calls can lead to unintended changes across multiple systems. Always test commands in a safe environment first.

The power of remote execution implies significant security considerations; ensure master and minion security best practices are followed.

COMMON USAGE PATTERNS

Remote Execution: Run an arbitrary command on targeted minions.
Example: salt '*' cmd.run 'uptime'

State Application: Apply a defined configuration state.
Example: salt 'webservers' state.apply apache

Targeting Specific Minions: Use various methods to select minions.
Example: salt -G 'os:CentOS' test.ping (target by grain)

Module Functions: Interact with Salt's execution modules.
Example: salt 'dbserver' pkg.install mysql-server

HISTORY

SaltStack was created by Thomas Hatch and first released in March 2011. It was designed to address the need for faster, more scalable configuration management and remote execution than existing tools at the time. A key differentiator was its use of ZeroMQ for high-performance communication, enabling near-real-time command execution across thousands of servers. Over the years, Salt has evolved significantly, adding robust state management, orchestration capabilities, cloud integration, and a vibrant open-source community. It was acquired by VMware in October 2020.

SEE ALSO

salt-master(1), salt-minion(1), salt-key(1), salt-call(1), ansible(1), puppet(8), chef-client(8)

Copied to clipboard