Remote execution & targeting
Run commands across the fleet instantly.
Remote execution is the fastest way to feel Salt’s power: salt ‘<target>’ <function> runs an execution-module function on every matching minion in parallel and returns their results. test.ping confirms connectivity, cmd.run runs a shell command, pkg.install installs a package, service.restart restarts a service — hundreds of functions across modules. This is imperative and immediate, the counterpart to declarative states.
$ salt '*' test.pingweb1: Trueweb2: Truedb1: True$ salt 'web*' service.restart nginxweb1: Trueweb2: True$ salt '*' pkg.version openssl # gather a fact from the whole fleet at once
Targeting
The target selects which minions a command hits, and Salt has many targeting methods: globbing on minion id (web*), grains (-G ‘os:Ubuntu’), pillar, subnet (-S), regex, or node groups defined on the master. Compound targeting combines them (-C ‘web* and G@os:Ubuntu’). Precise targeting is essential — it is the difference between restarting nginx on the web tier and restarting it everywhere.
$ salt -G 'os:Ubuntu' pkg.upgrade # target by grain$ salt -C 'web* and G@datacenter:us-east' cmd.run 'uptime' # compound$ salt -N webservers state.apply nginx # target a node group from the master config