Installing and configuring systemd with Salt

Setup

SaltMaster: DigitalOcean, 1gig, 1cpu, Ubuntu 18.04
SaltMinion: DigitalOcean, 1gig, 1cpu, Ubuntu 18.04

Pkg-File-Service

We are using Pkg-File-Service philosphy where you first install the package you need, test it. Then you move the preconfigured config file to your slave and test it and as last step you make sure the service will keep running.

pkg.installed

Fast recap from last weeks blog. For detailed explanation check here.

sudo apt update
sudo apt -y install salt-master
sudo apt -y install salt-minion
sudoedit /etc/salt/minion
sudo systemctl restart salt-minion.service
sudo salt-key -A

Lets first make the folder tree for our apache on our master

sudo mkdir -p /srv/salt/apache

sudoedit /srv/salt/apache/init.sls

Add this into init.sls

apache2:
  pkg.installed
sudo salt '*' state.highstate

Test it

file.managed

Add an index.html in your masters apache folder write inside “Hello world”

sudoedit /srv/salt/apache/index.html

Then add more text on init.sls

sudoedit /srv/salt/apache/init.sls

Add this under the apache2:…

/var/www/html/index.html:
  file.managed:
    - source: salt://apache/index.html

And test it. It should over write the default apache page

Allowing user to create websites

We need to activate the setting in apache that allows normal users to have folders in public web. It is done with

sudoedit /srv/salt/apache/init.sls

Adding this to the bottom of the file.

/etc/apache2/mods-enabled/userdir.conf:
 file.symlink:
   - target: ../mods-available/userdir.conf

/etc/apache2/mods-enabled/userdir.load:
 file.symlink:
   - target: ../mods-available/userdir.load

service.running

We need to make sure that Apache keeps running and restarts itself only when absolutely needed. Meaning when the user edits its website. This we can do with service.running and watch.

sudoedit /srv/salt/apache/init.sls

And adding this as the last thing to the file.

apache2service:
 service.running:
   - name: apache2
   - watch:
     - file: /etc/apache2/mods-enabled/userdir.conf
     - file: /etc/apache2/mods-enabled/userdir.load

The end result should look like this

Test it last time.

Sources:

https://tuomasolkinuora.wordpress.com/2018/10/09/configuration-management-systems-h1-and-h2/
Licence GPl v2 2018

Leave a Replay