Server management with salt – h1

This assignment was completed in full from my personal desktop, running Xubuntu 18.04.1 x64, and a virtual machine running Ubuntu 18.04.1 x64.

Installing salt (10:13)


I began by installing salt-master on my virtual machine and poking holes in the firewall. (Not for fun, salt needs them in order to function.)

master$ sudo apt-get update
master$ sudo apt-get install salt-master

master$ sudo ufw allow 4505/tcp
master$ sudo ufw allow 4506/tcp


I then installed salt-minion on my desktop computer.

minion$ sudo apt-get update
minion$ sudo apt-get install salt-minion

Salt is now installed. Next we need to tell the minion where to find the master.

minion$ cd /etc/salt/
minion$ sudoedit minion
master: master's IP
id: home

Master’s IP is pretty self explanatory.
Id can be anything, but if left blank will be automatically generated from the hostname.

Restarting salt minion at this point is required for the settings to take effect.

minion$ sudo systemctl restart salt-minion.service

Accepting the key (10:42)

master$ sudo salt-key -A

The following keys are going to be accepted:
Unaccepted Keys:
Proceed? [n/Y] Y
Key for minion home accepted.

I then tested the configuration by issuing some commands to my minion.

master$ sudo salt "home" "mkdir /home/petman/new_folder_from_master"

The above command created a new folder called “new_folder_from_master” to minions home directory.

States (11:25)

States are stored in /srv/salt
I first created a file named top.sls

base:             #idk what this does, but it's required
  'home':         #target a minion with ID="home"
    - hello       #execute a module called "hello"
    - installer   #execute a module called "installer"

My state will include two modules, “hello” and “installer”.


master$ sudo mkdir hello
master$ cd hello
master$ sudoedit init.sls

“Hello” module will copy greetings.txt from master to minion(s).

/tmp/greetings.txt:    #where to place the file @ minion
  file.managed:        #keyword to move stuff around
    - source: salt://hello/greetings.txt 
                       #^where to find the file @ master

I then created the greeting.txt file to the location specified above.

master$ sudoedit greetings.txt


master$ sudo mkdir installer 
master$ cd installer 
master$ sudoedit init.sls
xpaint:              #what to install
  pkg:               #keyword to install stuff
    - installed      #install the package

By default, salt minions check for updates every n minutes. I obviously didn’t want to wait, so i issued a command to make them do so immediately.

master$ sudo salt "home" state.highstate

As the picture shows, everything works great!

Grains (12:57)

master$ sudo salt "home" grains.item os osrelease
master$ sudo salt "home" grains.item cpu_model
        Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz


Leave a Reply

Your email address will not be published. Required fields are marked *