Exercise 10-1: Configuring salt Master and Minions

Topic Progress:

Exercise 1, Chapter 10 – Configuring a salt master and minion.

To configure a salt master and minion use commands similar to these. Note that some of the commands should be issued on the master, and some one the minion (or slave) as noted by the command prompts.

First, you should install the salt-master package on a server that is reachable by all the hosts that you want to manage and salt-minion on the hosts that you wish to manage. This will require two machines, or VM's. Set up one first. For the sake of demonstration, you can use two a live boot instance.

On the machine you intend to be the master:


master# apt-get install salt-master

If you are using your ISO from Exercise 5, Chapter 9, you can use that as the minion's install ISO. Otherwise, spin up another live VM for the minion and execute apt-get install salt-minion:


minion# dhclient eth0 # Or any other network setup you prefer
minion# apt-get install salt-minion

Next, each minion must be told where to find their master. Simply edit /etc/salt/minion and set the master key to the DNS name (or IP address) of the Salt master:


minion# nano /etc/salt/minion
minion# grep ^master /etc/salt/minion
master: 192.168.122.105

Each minion has a unique identifier stored in /etc/salt/minion_id, which defaults to its hostname. This minion identifier will be used in the configuration rules and as such, it is important to set it properly before the minion opens its connection to the master:


minion# echo kali-scratch >/etc/salt/minion_id 
minion# systemctl enable salt-minion
minion# systemctl start salt-minion

When the salt-minion service is running, it will try to connect to the Salt master to exchange some cryptographic keys. On the master side, you have to accept the key that the minion is using to identify itself to let the connection proceed. Subsequent connections will be automatic:


master# systemctl enable salt-master
master# systemctl start salt-master
master# salt-key --list all
master# salt-key --accept kali-scratch

As soon as minions are connected, you can execute commands on them from the master. Examples:


master# salt kali-scratch cmd.shell 'uptime; uname -a'
master# salt kali-scratch sys.doc disk.usage
master# salt '*' service.enable ssh
master# salt '*' service.start ssh
master# salt '*' pkg.refresh_db
master# salt '*' pkg.upgrade dist_upgrade=True