Server management with salt – h3: Git and Markdown

This assignment was completed in full from my personal desktop, with a live-USB running Xubuntu 18.04.1 and a virtual machine running Ubuntu 18.04.1

One of the assignments this week was to write the report completely in markdown. I also wanted to keep the blog going, so i did both.

This assignment was completed in full from my personal desktop, with a live-USB running Xubuntu 18.04.1 and a virtual machine running Ubuntu 18.04.1

/srv/salt git repository (16:58 – 08.11.)

I began by establishing an SSH-connection to my web-server, that currently also works as my salt-master. After logging in, i navigated to my salt folder.

cd /srv/salt

To turn this into a git repository, we will first need to make a new GitHub-repository. (See image below) I took backups of the files inside the original salt folder, and deleted it. Next, i copied the repository address from github, (see image below) and issued a command:

git clone

This cloned the github repository (called salt) to /srv, thus reconstructing my salt path, while also working as a git repository. I then moved my salt modules to this new folder, and issued these commands to push my files to the repository.

git add .
git commit
git pull
git push

Bonus content – git credential caching (17:24)

In order to authenticate your push-requests, GitHub asks for your account name and password. To save time, you can issue this command to cache your credentials and save valuable time that could be spent on something else:

git config credential.helper cache
git push
Username: <type your username>
Password: <type your password>

[work for n minutes]
git push
[your credentials are used automatically]

Commands are from this article

git log, git diff, and git blame (17:41)

git log

$ git log
commit 4d669b0e7a6e62ab4a538b8b52fab0340073dc98 (HEAD -> master, origin/master, origin/HEAD)
Author: Petrus <>
Date:   Thu Nov 8 11:28:00 2018 +0000

    some salt modules

commit 07ec1bb501bec605f06e470f7c164d1b1f58f81e
Author: Pheebzer <>
Date:   Thu Nov 8 11:20:36 2018 +0000

    Initial commit
  • commit – Identifier for this specific commit. (SHA-1 checksum)
  • Author – Author’s name and email
  • Date – Time and date the push-request was made.
  • Comment left by the author.


git diff

$ git diff
diff --git a/top.sls b/top.sls
index 754be4f..f317884 100644
--- a/top.sls
+++ b/top.sls
@@ -1,3 +1,3 @@
-  'h2':
+  'testi123':
     - apache_installer

Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, changes between two blob objects, or changes between two files on disk.


Diff only shows one change here for the same reason git log only showed one commit: thats all the changes that i have made so far.

git blame

$ git blame top.sls
4d669b0e (Petrus            2018-11-08 11:28:00 +0000 1) base:
00000000 (Not Committed Yet 2018-11-08 16:29:15 +0000 2)   'testi123':
4d669b0e (Petrus            2018-11-08 11:28:00 +0000 3)     - apache_installer

Annotates each line in the given file with information from the revision which last modified the line. Optionally, start annotating from the given revision.


git reset-hard

I made a “stupid mistake” in my salt files by removing top.sls

sudo rm top.sls

I then used the git reset --hard HEAD to undo the changes.

$ sudo git reset --hard HEAD
HEAD is now at 4d669b0 some salt modules

New salt module (18:50)

I decided to modify my apache_installer to also install php, and allow it to be used in user homepages.

I started by doing the installation by hand.

sudo apt-get update
sudo apt-get install libapache2-mod-php

I then commented out the necessary parts of php7.2.conf, and restarted apache.

Everything works, its time to automate the process with salt! This is what my init.sls looks like:



    - source: salt://apache_installer/index.html

    - source: salt://apache_installer/php7.2.conf

    - target: ../mods-available/userdir.conf

    - target: ../mods-available/userdir.load

    - target: ../mods-available/php7.2.conf

    - target: ../mods-available/php7.2.load

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

    - source: salt://apache_installer/public_html
- include_empty: True

This module:

  • Installs apache2 and php7.2
  • Creates a public_html folder with an index.php file
  • Creates symlinks to turn on userdir and to enable php in said directories
  • Watches those files to prevent changes

Bonus content – Turning markdown files to html via Pandoc

In order to feed this text to wordpress, i need it in html format. This is where Pandoc comes handy.

sudo apt-get install pandoc
pandoc -o h3.html


Leave a Reply

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