Today I’m taking a look at SaltStack pillars. Pillars, in short, let you define secure data that is sent to each minion. If you want to take a closer look at the concept, be sure to check out SaltStack’s page: https://docs.saltstack.com/en/getstarted/config/pillar.html
In this task I used two virtual machines that were both running Xubuntu 16.4.04. Both machines had 1GB of dedicated RAM and 10GB for storage. The virtual machines acted as minions and my master was a previously created virtual server from DigitalOcean.
This post is part of a server management course I’m attending, taught by Tero Karvinen.
Variable editing with pillars
My first task was to edit a variable in a file with pillars. The goal was to serve different information to two different minions. After a brief consideration, I decided to serve an index.html file into the folder /etc/skel/public_html on both machines so that new users on them would have their own sites instantly. I would change the index.html so, that each minion would have a site that displayed their hostname. Since both machines were already running Apache and the user directories were enables, all I needed to do was to set the files on the master (if you need help with Apache or its user directories, you can check out my earlier post: https://oliverlahti.com/2018/02/07/installing-testing-and-running-apache/)
I started by creating a new folder for the pillars with sudo mkdir /srv/pillar:
After this I quickly connected my virtual machines to the master:
My minions were called “olimin” and “vermin”. After this I made the state file I needed with sudoedit /srv/salt/verminskel/init.sls:
I copied the same file to /srv/salt/oliminskel. Next I created the index.html file that I defined on the state file and placed it in /srv/salt:
Since I had defined the pillar usage in the state file, I needed to create a pillar state file. I created two files that corresponded to the names I used in the salt folder; oliminskel.sls and verminskel.sls. In these I only placed a short statement containing the value I wanted for the variable:
I created a version for both vermin and olimin. After this I created a top.sls file that I placed in both the pillar and salt folders:
With all the files I created, I was ready to apply the highstate. I used sudo salt ‘*’ state.highstate to use the top file. This seemed to work out fine:
Now I was ready to see, if things worked out as they should’ve! I took a peek to the skel folders on both minions and saw that the index.html was transferred correctly. However, I wanted to see it in action, so I created a new user called “minion” on both minion machines and tried to access their websites:
Obviously the process was successful. I still wanted to see what the information was that the pillars actually transferred, so on the master I typed sudo salt ‘*’ pillar.items:
Here I saw that the variable “site” was replaced with the correct hostnames, as they were defined in the pillar folder’s sls files. From this I concluded that I was finished.
Using pillar.get for a single minion
Next I needed to change my files so, that one of my minions would be getting the variable value from the pillar.get statement. I did this by adding the pillar.get to both init files under verminskel and oliminskel:
Now, if the pillars wouldn’t provide a value for the variable, it would get the value “unknown”. To make this possible, I removed everything from the oliminskel.sls in the pillar folder:
Now everything was set up and I was ready to test the changes. I applied the top file again with sudo salt ‘*’ state.highstate. To check the results, I again created new users on both minion machines, this time named “alainen”. Here are the results:
As you can see, the process worked as intended. Olimin got it’s value from the pillar.get. And so my task was completed!
http://terokarvinen.com/2018/aikataulu-%E2%80%93-palvelinten-hallinta-ict4tn022-4-ti-5-ke-5-loppukevat-2018-5p – The course I’m attending
https://docs.saltstack.com/en/getstarted/config/pillar.html – Info on pillars