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 minion or group of minions you would like to run a function on.
- General Targeting
-
List available grains on all minions:
salt '*' grains.ls
Ping a specific minion:
salt 'web1.example.com' test.ping
- Glob Targeting
-
Ping all minions using a domain:
salt '*example.com' test.ping
Display the OS name of all minions 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 minion IP addresses:
salt '*' network.ip_addrs
Ping a specific minion IP address:
salt -S '172.31.60.74' test.ping
Ping all minions on a subnet:
salt -S 172.31.0.0/16 test.ping
Lookup a Subnet Using theip
CommandYou can use the
ip
command to find the subnet mask in the format of192.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 minions 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