Salt Calls

Salt Calls

Salt calls are defined by three main properties:

salt 'target' <function> [arguments]
Target

Use the second property in a Salt call to target a single machine or group of machines. Specify the client or group of clients you would like to run a function on.

General Targeting

List available grains on all clients:

salt '*' grains.ls

Ping a specific client:

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

Ping all clients using a domain:

salt '*example.com' test.ping

Display the OS name of all clients with the webserver label:

salt 'webserver*' grains.item oscodename
List Targeting
salt -L 'webserver.example.com,db.example.com' test.ping
Regular Expression Targeting

You may use PCRE-compliant regular expressions:

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

List client IP addresses:

salt '*' network.ip_addrs

Ping a specific client IP address:

salt -S '172.31.60.74' test.ping

Ping all clients on a subnet:

salt -S 172.31.0.0/16 test.ping
Lookup a Subnet Using the ip Command

You can use the ip command to find the subnet mask in the format of 192.168.1.1/24:

ip -o -f inet addr show | awk '/scope global/ {print $4}'
Function

Once you have specified a target, provide the function you would like to call. Functions also accept arguments. Arguments are space-delimited, for example:

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

Find more functions which can be called on clients by running:

salt '*' sys.doc

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

Arguments

Provides the extra data needed by a function you are calling. The command pkg.install requires an argument specifying a package to install. YaST has been selected for installation, for example:

salt '*' pkg.install yast2