Pkg-file-service & salt states (h2, tiistain ryhmä)

Creating a salt state which enables Apaches users’ homepages. At first, installing everything manually on master: sudo salt ‘*’ pkg.install apache2
After that, enabling the userdir module: sudo a2enmod userdir
Then I created a directory named public_html, changed permissions (chmod 777 public_html) and created a file index.html. Then I could access the site via webrowser.

Let’s try to automate enabling user homepages on slaves by creating a state. I used as an example.
First error occured when I tried applying the state.

Error was fixed by removing one colon.

After fixing the error above, I applied the state again and this time it seemed to work.

At first, I hadn’t created a “default-index.html” file so I got this error. Everything else seemed to work as they should. I just had to manually create a public_html directory to set a user homepage.

After creating “default-index.html” file under the /srv/salt/apache/ directory, and applying the state again, apaches homepage was replaced by file I had just created.

Next step was to enable php to function on users’ home directories as well. I installed php and made some modifications on apaches conf files. I did this manually on salt master, to make sure everything works before making a state. First I had to install php: sudo apt install php libapache2-mod-php after that, I made slight modifications to php7.2.conf file. I found a tutorial on ubuntus site how to enable php on user dir which helped me to get this working:
And after restarting apache daemon, php worked on my home directory.

After commenting the last five lines out, php worked on home directory.
I made a file called “info.php” which is a test file to test if php is working. File contains little piece of php code:

Then I wanted to make above steps to happen automatically. So I made a state.

State for enabling php on user directories.
Modified php.conf file.

Problems I encountered was few syntax errors when writing the state and wrong file name in source file. After fixing those errors, I created info.php file on slaves to test if it was working.

And it was.

In this task, I created a state that would set up name-based virtual host on apache. I haven’t done virtual hosts on apache before, so I configured that manually first. I found a handy tutorial for doing that:
So basically what I did was create directories for both of virtualhosts, make configuration files for them and tell apache to use them.

Oops, some errors. I had a typo on one of the conf files. Fortunately I didn’t broke anything.
State for virtual hosts.
State didn’t function as wanted.

I couldn’t get example homepages work for new users. I was able to make a state which would create a index.html file for new users, but it didn’t work as I wanted.

I had to create a public_html directory and move the index.html file there to make it work.


Leave a Reply

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

You are commenting using your 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