Linux Server Management Assingment 2 – Salt state

H2 Pkg-File-Service

Assignment given by Tero Karvinen

Tehtävät tästä eteenpäin (h2, h3…) tulee ratkaista tekemällä Saltin tila (state), ellei tehtävänannosta muuta ilmene. Tee ensin käsin, automatisoi vasta sitten. Muista testata lopputulos.

a) Opiskele yllä aikataulussa olevat artikkelit. (Tätä lukutehtävää ei tarvitse raportoida). Luettava materiaali on kunkin tapaamiskerran kohdalla, esimerkiksi nyt “2. Package-file-server. […] Luettavaa: Karvinen 2018: Pkg-File-Service – Control Daemons with Salt..”

b) Laita käyttäjien kotisivut toimimaan Apachella.

c) Laita PHP toimimaan käyttäjien kotisivuilla. (Huomaa, että PHP toimii oletuksena kaikkialla muualla kuin käyttäjien public_html-kotisivuilla.)

d) Rakenna tila (state), joka tekee Apachelle uuden nimipohjaisen virtuaalipalvelimen (name based virtual hosting). Voit simuloida nimipalvelun toimintaa hosts-tiedoston avulla.

e) Tee tila, joka laittaa esimerkkikotisivun uusille käyttäjille. Voit laittaa esimerkkikotisivu /etc/skel/:iin, niin se tulee automaattisesti ‘adduser tero’ komennolla käyttäjiä luodessa.

f) Eri asetukset. Tee Package-File-Service tilalla eri asetuksia kuin ne, mitä tehtiin tunnilla; ja eri kuin mitä teit/teet h2 muissa kohdissa. Voit muuttaa jotain toista asetusta samoista demoneista tai valita kokonaan eri demonit.


Testing Environment

For this assignment I used Laptop Asus model RS17S and live-usb with Ubuntu 18.04. When I am using live-usb so to download some programs I have to go Software & Updates and check the Community-maintained free and open-source software (niverse)

Selection_001.png


a) First assignment was a reading assignment: Pkg-File-Service – Control Daemons with Salt – Change SSH Server Port, Apache User Homepages Automatically – Salt Package-File-Service Example. [Official] Salt Tutorials: How Do I Use Salt States?, States tutorial, part 1 – Basic Usage, Salt Best Practices.


b) Apache homepage

I had to make Apache work for every user. First think I had to do is to do it by my hand and then automate it.

I have installed Apache before on my blog. So I won’t report it on my blog again.

Mozilla Firefox_002.png

I got apache working by hang on my local computer so I could continue making it automated. Before that I had to remove Apache from my local computer:

$ sudo apt-get purge apache2 apache2-utils apache2-bin apache2-data

$ sudo rm -rf /etc/apache2

$ sudo apt-get autoremove

$ sudo apt-get update

Now I could start making it automated. For instruction I looked from my teacher’s site.

First I created a new file, where inside I created 2 files which would install apache and run it:

$ cd /srv/salt/

$ sudo mkdir apache

$ sudoedit index.html

$ sudoedit init.sls

$ cd ..

index.html:

Selection_003.png

init.sls

Selection_004.png

After I created this files I had to apply them:

$ sudo salt ‘minion1’ state.apply apache

Selection_005.png

Selection_007.png

(While doing this I had a small type error:

Selection_008.png

I forgot ‘:‘ at the end of /var/www/html/index.html: . So I had to fix that so that this would work. After adding what I missed it worked!)

After a while when it installed everything it had to installed I went to localhost on my browser and it worked.

Mozilla Firefox_009.png

Then I created a public_html folder and an index.html file. I could also automate this, but I have only started to learn this so I’m going to test and update this page.

$ cd

$ mkdir public_html

$ cd public_html

$ nano index.html

Selection_010.png


c) PHP

I have before installed PHP on my blog.

This assignment is done like the previous but I have to change the init.sls file and I also change a bid the init.sls then on the previous assignment.

So this is what my init.sls looks like. I added php package for download also with apache. Here I again used my teacher code.

robert@512mb: -srv-salt-apache_024.png

For php to work on users homepage we have to comment few rows in a .conf file.

I copied the .conf file the the /srv/salt/apache/ and after copy I comment the necessary lines.

$ sudo cp /etc/apache2/mods-available/php7.0.conf php7.0.conf

$ sudoedit php7.0.conf

robert@512mb: -srv-salt-apache_025.png

Then I had to change the init.sls file and to add the php7.0.conf. For adding I used the file.managed. I also added the index.php what I am going to change next.

robert@512mb: -srv-salt-apache_014.png

This step isn’t necessary but I wanted to try if this would make any difference. In the end it didn’t! It just created a .php file into /var/www/html.

Now because I made index.html and now I am doing php assignment I had to change that .html to .php

$ sudo mv index.html index.php

And I add some php content inside.

Selection_013.png

I also changed on my minion computer the index.html to index.php and added something to there to.

$ cd public_html

$ mv index.html index.php

ubuntu@ubuntu: ~-public_html_015.png

Checked on my browser that my php isn’t working yet.

Selection_016.png

Now on my master I had to run the apply command to my minion.

$ sudo salt ‘minion1’ state.apply apache

I instantly had some whitespace error that I had to fix!

robert@512mb: -srv-salt-apache_017.png

I had the first lines wrong where I am installing the packages! I corrected lines and now the init.sls looks like this.

robert@512mb: -srv-salt-apache_018.png

Now I had to apply it again!

$ sudo salt ‘minion1’ state.apply apache

robert@512mb: -srv-salt-apache_022.png

Now it is visible that it changed lines in the .conf file.

Selection_023.png

Installation worked and now I can see that it counted the php calculation.

What I noticed!

While doing this assignment I noticed that newest php it downloaded was php7.2 but on my server I had a bit older version php7.0. So while I was trying to change php7.0.conf and why it didn’t work. I had to changed the file php7.0 -> php7.2.


d) Hosts Virtual page

On this assignment I had to do a state that would make a new name based virtual hosting.

First I did it manually on my minion. I edit the hosts file and added a new address.

$ sudoedit /etc/hosts

127.0.0.1 http://www.example.com

ubuntu@ubuntu: ~-public_html_026.png

Mozilla Firefox_027.png

The address had changed so it worked. This is just a default localhost site but I changed it so now it is also what I have assigned it to.

Before automating this I deleted the new line in the hosts file.

Automating

I copied the hosts file on my server to the /srv/salt/apache/ folder and added the new file.

$ sudo cp /etc/hosts hosts

$ sudoedit hosts

Selection_028.png

After hosts file I created a file that will apply this but I can’t use the init.sls file.

$ sudoedit example.sls

Selection_031.png

Then I applied this example.sls file.

Selection_030.png

It changed lines in hosts file. Then I navigated to that site http://www.example.com

Selection_032.png

The address worked!


e) Skel

I started doing this manually. First I made a new folder and a file to /etc/skel and then added a new user. Help I used to do this assignment I look on SaltStack documentation

$ sudo mkdir /etc/skel/public_html

$ sudo nano /etc/skel/public_html/index.html

$ sudo adduser testuser

Selection_033.png

So when I created new user, he had an public_html folder with index.html file inside. Now I could start making this as an automated part. Before I started to automate this I deleted the public_html folder.

$ sudo rm -r /etc/skel/public_html

First I created and public_html folder with index.html file than a .sls file that would process the state from master to minion.

$ cd /srv/salt/

$ sudo mkdir public_html

$ cd public_html/

$ sudoedit index.html

Selection_034.png

$ cd ..

$ sudoedit skel.sls

Selection_035.png

$ sudo salt ‘minion1’ state.apply skel

Selection_036.png

We can see that it created a new directory and a file. Now I cat tot create a new user and see that did it worked!

ubuntu@ubuntu: ~_037.png

Selection_038.png

It worked!!


f)


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s