In this recipe, we have seen how to apply Salt states to minions. Let's now look at the steps in details.
First, we tested if the certificate request for the minion had been accepted and signed by the master because we had configured it to accept all minions by defining the wildcard in the /etc/salt/autosign.conf
file.
Next, we tested communication between the master and the minion with the salt
binary and using what we call built-in execution modules in Salt. The test.ping
module checks if the minion is available and is responding to the master and grains.items
returns all the built-in and custom grains on the minion. Here, test.ping
and grains.items
are the execution modules and are just a couple of the numerous modules available in Salt.
Next, we look at how to actually apply the configured states to minions.
First, we see the push mechanism from the master to the minion:
Here, we see the salt
binary being used along with the name (minion id
) of the minion, followed by another execution module state.sls
, and then the name of the state that we had configured. Finally, the name of the environment is specified without which Salt will look for the base
environment and fail. Any configured state can be used in this format to apply to minions, and this method is independent of the top.sls
file that we configured in the base directory of the development
environment.
Next, we see an alternate method to apply states to minions:
Here we see the same command, without the state name and a new execution module called state.highstate
. When state.highstate
is mentioned, it applies all the states that have been configured for the minion in the top.sls
file of that environment. Only the user
state gets applied to the minion because that is the only state we have configured in top.sls
so far.
The third command produces a slightly different output:
This command has a new option and its value is --state-output=terse
. This option is specified if we do not want a detailed output as the first and second commands. However, it does the same task as the first and second commands
Next, we look at the method of doing the same task by fetching the states on the minion from the master by using the pull mechanism:
Here, we used the salt-call
binary, which is available only on Salt minions along with the state.highstate
execution module. This command will automatically take the environment from the minion configuration file, that is, /etc/salt/minion
and look for the minion states in the development
environment and apply all the states configured for this minion in the top.sls
file. Note the output, we see the minion caching all required data in the system from the master before applying the states. This caching process will take place each time the data in the master changes and the salt-call
command is run.
The other method (not used very often) to apply specific states to the minion and from the minion is shown next. These states can also be part of highstate
, if added to the top file:
Here, we see the minion using the salt-call
binary, but mentioning the state.sls
execution module to specify a particular state instead of all the states, that is, the user
state. However, do note that, for this to be successful, the Salt environment must be mentioned as shown, without which it will look for the base environment and fail.