Getting started with SaltStack



Ubuntu 18.04 server on digital ocean
1 core 1gig ram


Ubuntu 18.04 digital ocean
Linux mint 19 Ryzen 1600, gtx 1060
First update everything runing

sudo apt update && sudo apt ugrade -y

Creating Salt Master

sudo apt-get -y install salt-master
hostname -I

Creating Salt Minion

First install the salt minion and edit the minion file to ad your master ip and slave id

sudo apt-get -y install salt-minion
sudoedit /etc/salt/minion

Add this

id: minion1

Somehow my virtual mashine was not connecting to the master even it was done right. So I made my own pc runing linux mint 19 to a minion. I also made a local slave on the same host as master.

Restart your salt-minion service

sudo systemctl restart salt-minion.service

Connecting slave

In master write and accept the new slaves.

sudo salt-key -A

Test your setup with

sudo salt '*' 'whoami'

Im not sure what those errors are. But we have a connection.

Collecting Brains…

I mean Grains

The master can brainwas the slaves in releasing their secrets with

sudo salt '*' grains.items

For example it will show us the processor that digital ocean is running my virtual mashine.


Want to make more complex things than just single commands? With salt you can declare things like “I want that Firefox is installed”. No matter how many times you run the command it will always check if your wish is granted if it (Firefox is installed) it will not do anything to the minion. This is called Idempotency

First we need to make a new folder on the Saltmaster where to store the rules for the minions.

sudo mkdir -p /srv/salt/

Make a new hello.sls file these are always written in YAML.

sudoedit /srv/salt/hello.sls

Add inside to file this. It will put the file “hello.txt” to all your slaves temporary folder

    - source: salt://hello.txt

Add a file called hello.txt in to the same folder as hello.sls and write inside what ever you like. I will put “See you at”

sudoedit /srv/salt/hellotero.txt

To apply it to your slaves just run.

sudo salt '*' state.highstate

Apply these automatically

If want to run something to all minions by default just make a file named “top.sls”. All minions will periodically ask the master if everthing is as the top.sls says and will change themself accordingly.

Does firewall matter?

It does not. The beauty lies in salt being a “pull” design. Meaning that the minions will contact the master and not the other way around. So it dosent matter what ip or firewall the minion has. Only know domain or ip in the setup needs to be the master IP.


Copyright GPLv2 2018

Practice exam

Exam practice

This is a practice run for next weeks final exam for the Linux server course.

The idea is to choose one of the old exams and i chose this one.

Lamp stack

We need to create 7 users with their own public_html with an index file. Here are the users. Jorma wants a own domain named this we will make with an hostfile and sites-available .conf. Maija is the new sudo admin and as the boss she wants to choose her own username what will be maija.
Jorma Mähkylä jmahk gieP1ugh6eu
Pekka Hurme phurm engooR1ocha
Ronaldo Smith rsmit IeyiexeeP2a
Håkan Petersson hpete iereiteeH7E
Einari Mikkonen emikk queej8EvahY
Einari Vähäkäähkä evaha quab9Xayei3
Eija Vähäkäähkä eijav moJ4zoogiem
Maija Virtanen maija AhB4Oo2nohy sudo

First we will edit the skeleton folder which is the base to all newly created users. We can add the public_html folder with the index.php file already inside in to the skeleton so all users get it automatically. The web page of each user needs to display to current user so we need to make some kind of script for that. Lets try getting it with php so first install LAMP stack. As we did in the last time.
So here are the commands in order with only tiny descriptions what they do.

Update fresh Linux, install and configure Apache

sudo apt update && sudo apt upgrade -y
sudo apt install apache2 -y
echo "Default"|sudo tee /var/www/html/index.html
sudo a2enmod userdir
sudo systemctl restart apache2
cd; mkdir public_html; cd public_html
echo 'User created Apache works!'> index.php

Lets create the first user to test Apache for normal users.

sudo adduser jmahk
cd; cd public_html; echo 'Php works if it says four > <?php print(2+2+"\n\n"); ?>'> index.php

Now we know it works so lets put that inside the skeleton and add in the index.php this part so it will show “Welcome” and the current user name.

echo   get_current_user();

Now we can create all the other users too with the “sudo adduser” command and remember to give Maija sudo privliges. With typing

sudo adduser maija sudo

Firewall and python script

Now we enable and configure firewall

sudo ufw allow 22/tcp && sudo ufw allow 80/tcp && sudo ufw allow 443/tcp
sudo ufw enable && sudo ufw status


print “Welcome back!”

Adding host name for jorma

 cd /etc/apache2/sites-available/
sudoedit jorma.conf
sudo a2ensite jorma.conf

Copy this inside jorma.conf

<VirtualHost *:80>
    DocumentRoot /home/jmahk/public_html/index.php

Then we activate the site and edit the hosts file.

 sudo a2ensite jorma.conf
 systemctl reload apache2
 cd /etc/ ; sudoedit hosts

and add this 2 lines


Kurssiguru-coding meta packet

I tried to do it with this guide but was unsuccessful it gave me an error
dh_installchangelogs: warning: debian/changelog(l2): found end of file where expected first heading
dh_installchangelogs: error: fatal error occurred while parsing debian/changelog
debian/rules:20: recipe for target ‘binary-indep’ failed
make: *** [binary-indep] Error 255
Error in the build process: exit status 2


Course assignment
Chosen practice exam
My lamp stack blog.

PHP JavaScript Python coding first steps

It’s good to know at least the basics of coding in different languages and this week’s assignment we had to write Hello world in three different programming languages.

So, lets get started with JavaScript!

JavaScript is a popular language that runs the web. Now days it runs also android apps and even the web backend.

print("Hello World");

See that’s not that hard you just need to remember JavaScript always ends with Semicolon. (Don’t trust me I don’t know how to code.)


You may often hear that PHP is a mess because you can write almost anything in many multiple ways, so nothing is consistent. Still php is one of the most important languages it also runs large parts of the web.

print("Hello World");


Python is a very big language what you can use in almost anything. Web development, science programs, AI, Big data etc. And seems to be the polar opposite of PHP. IF you watch videos on YouTube about python its always stated that Python is a very strict language whit one way to write something. It has its advantages and disadvantages. Because of that its really easy to others to understand your code and vice versa.

print "Hello World"

As you see Python seems to have the most user-friendly syntax it has been designed for good readability but if you write anything longer you need to be careful with the indentations those matter a lot in Python. But you don’t need to play around with parenthesis as much than in other languages.


This was written with markdown. If you want to know how.
My school assignment. This was part “h6”