We're going to start taking a look at our Salt modules. In Salt, we have
different modules for remote execution commands and for state commands. Our
remote execution modules, remote execution is very similar to the ad‑hoc
commands that we have in Ansible and Puppet; they are just run directly from
the command line, and we don't have them stored in any long‑term configuration
file, such as pkg.install.
Pkg is our module, .install is a function from that module.
Now if we take a look then at our state modules,
state files are more like our Puppet manifests or our
Ansible playbooks, so they are long‑term configuration. And
when we take a look at the module,
the module name is the same, but it is a different module,
but the function is completely different.
Instead of pkg.install, it would be pkg.installed,
if we wanted a package installed.
So just be aware,
there are slight differences from the command line execution to state
file execution. Documentation is really good, though,
and fully supported, both through the web and on our command line.
If we look at our documentation with salt‑call, then we can
go through and do a sys.list_module, and this will list our
remote execution modules.
If we go through and then look at sys.list_functions.pkg, it will be
the functions from the pkg remote execution module.
If we want full documentation, then that's where sys. comes in. Again,
documentation on our remote execution modules and pkg.install
where we then mention the module and the function that we'd
like to see the documentation on.
Now, to me, this seems like an introduction then to a command line
environment where we can go through and look at our documentation,
maybe list our modules,
lists and functions, and maybe as well as installing software,
we'll take a look at adding host entries. And look at
this. The glorious command line again.
And I say glorious because this is the glorious environment
where your learning truly does begin,
especially where you're following along on your own demonstration systems.
Now,
when we're using our Salt commands, we elevate our privileges with
sudo. Salt‑call, remember, we're executing on the Salt minion,
‑‑local, so we're not connecting back to our master, and we want to
read the documentation. So we can drop into our sys module and pull
out the list_modules function.
And, of course, then we're going to get a list of all of the modules.
Now, these are our remote execution modules,
modules that can be executed from the command line.
If we go through and we want to dig down a little bit more,
then we can use list_functions to see the functions from a
module, and let's take a look at our pkg,
our packaging module.
So we can see then there are a range of different
functions available from the module.
Okay? Now we can dig more into the documentation for a particular
module and function, so sys.doc.pkg. And then dot, and let's look
at installing software, pkg.install.
Now, of course, then, we've got reasonably verbose help,
but it is very, very good.
So we can page back,
we can see what we need to do, but it is relatively straightforward.
If we wanted to install some software,
let's go back then and change to the pkg module,
the .install function, so at the remote execution commands, we're
saying we want to install the software. In a state file,
we'll say we want the software to be installed.
The package we're dealing with is vim‑data.
This is going to give me syntax highlighting for our YAML
state files that we will see later.
Hit the big Enter key, and then Salt will do the work.
Now this is still very good because we don't need to be concerned about the
packaging software involved; it is chosen by the local minion.
And, of course, if I go through and execute it again,
we're not going to get any errors.
It'll just come back and say, no, I meet the required configuration.
So the same thing as we've seen with all of our other utilities, but we
might find that dealing with software packages now,
just getting a little bit passe, so if we go through and list our modules
again and maybe look for the word host, and look at this,
we've got a hosts module, for managing your local hosts
file. So let's play around with this.
If I then go through and look at the functions from the hosts module,
we can see that we can add hosts.
So if we go through then and run our hosts.add _host, and we're going to
add a local record into our host file, we're just going to put something
simple, but maybe 8.8.8.8, and then google as the hostname. Hit the big
Enter key, and we've now got that entry in our local host file. And it's
as simple as that.
If we go through now, and, of course, ping Google, we're getting our response.
So hopefully, this has been an introduction to you to both
the documentation and how we can execute commands from our
command line using Salt.
Obviously, we've been using the masterless setup, but this
would work in the same way if we were using a Salt master to target all of our minions.