Salt Command

Salt commands have three main components: target, function, and arguments. The calls are constructed in this format:

salt 'target' <function> [arguments]

The target defines the client, or group of clients, on which to run the function.

The function is the particular task to be run.

Arguments provide any extra data required by the function.

1. Salt Targets

Salt command targets allow you to specify a client or group of clients. There are several different targets you can use.

General Targeting

List available grains on all clients:

salt '*' grains.ls

Target a specific client:

salt 'web1.example.com' test.ping
Glob Targeting

Target all clients using a particular domain:

salt '*example.com' test.ping

Target all clients using a particular label:

salt 'label*' test.ping
List Targeting

Specify a flat list of clients, using their IDs:

salt -L 'client_ID1, client_ID2, client_ID3' test.ping
Regular Expression Targeting

You can also define targets with PCRE-compliant regular expressions:

salt -E '(?!web)' test.ping
IP Address Targeting

List available client IP addresses:

salt '*' network.ip_addrs

Target a specific client IP address:

salt -S '172.31.60.74' test.ping

Target all clients on a subnet:

salt -S 172.31.0.0/16 test.ping

2. Salt Execution Modules

When you have specified a target, provide the module and function to execute on the target.

Find which modules can be executed on the target:

salt '*' sys.doc

For a full list of callable modules, see https://docs.saltstack.com/en/latest/ref/modules/all/index.html.

3. Salt Function Arguments

Functions accept arguments for any extra data.

For example, the pkg.install function requires an argument specifying which package to install:

salt '*' pkg.install yast2

You can provide more than one argument to a function, with spaces between them. For example:

salt '*' cmd.run 'echo "Hello: $FIRST_NAME"' env='{FIRST_NAME: "John"}'