Executing Basic Commands with Salt

  • Salt shines with rapid, parallel remote command execution capabilities. With can execute commands using the salt command. Salt has its own command capabilities as well as having the ability to run native commands as if we were at the shell.

    First, native commands are simple to run:

    salt '*' cmd.run 'uptime'

    This executes the command uptime on all of the machines listed in the environment. The first argument is the wildcard * which tells us that every machine will run the command. The cmd.run argument tell Salt to run a raw command and the final argument is the command itself.

    Second, we will run a native command. Salt has many useful built in commands that we can run. We will show a couple of examples here:

    salt '*' disk.usage

    This returns the disk usage details from each machine in the environment. Of course, instead of using the wildcard we could target a specific machine or group of machines. Here we will run the same command but only on the machine names minion2.

    salt 'minion2' disk.usage

    We can use Salt's command execution capability to "manually" install a package to an individual machine (or group of machines or every machine, of course.)

    salt 'minion3' pkg.install wget

    Very useful. With the salt command we can replace tedious and slow SSH sessions and remote logins with something more secure, less effort and much faster. On a single machine, this is relatively unimportant. Once we start to tackle multiple machines this becomes rapidly more useful, even in a non-DevOps style mode. We can do most system administration tasks directly in this way, but with less effort and more efficiency. In this way, our Salt Master can become rather like a Jump Box but with some very handy benefits.

    Now we will list available, network interfaces:

    salt '*' network.interfaces

    Welcome to just the beginning of the power of Salt!