SaltStack - Apache Formula for Debian OS Family
Take a look at how you can set up your Apache formula and tear it down with this quick tutorial on your Debian OS system.
Join the DZone community and get the full member experience.Join For Free
Salt Stack – Apache Formula
As the blog specifies, here we are going to discuss the Apache formula which installs Apache on the Debian systems. Firstly, let’s discuss the requirements and then see the implementation of the formula.
Let’s say that we have a small set of Debian servers which is salted. We want to install Apache, wherein we have a custom configuration file with the necessary ports and user groups.
So, when we look at the requirements we will understand that our Apache formula should consist of an init state, a restart state, and a config file management state. What does each of them do?
Init.sls – In init state, we are going to install the Apache package, start the package, and make sure it is in running state
Config.sls – In config.sls, we are going use the salt function file.managed for managing all our files via Salt.
Restart.sls – Why do we need restart.sls?
Basically whenever there is change in the config file, we would need to restart the service in order for the changes to take effect.
The file_roots determines where the state files are stored. By default, all of the state files should reside at the location /srv/salt. If you would like to choose a different directory change the location in the /etc/salt/master file.
Let Jump Into Implementation
Firstly, make sure the file_roots is updated to /srv/salt in /etc/salt/master file.
Now, let's create a directory, /srv/salt. Let navigate to that directory and create a folder called apache. This is the folder where we will have our state files.
You can download the files from the GitHub repository.
Here we are installing the Apache package and starting the service.
We will be using the file.managed function to update the apache2.conf file. The source file will be usnder the /apache/debian-apache2.conf
dsWhenever there is config changes made to the Apache configuration file, our Apache service needs to be restarted. Here we are going to use the watch state to check if there are any changes made to the apache conf file.
Make sure to copy the debian-apache2 config file in the apache/config folder of master.
Now it’s the time to use the formula. To test the formula, use the command with sudo permissions:
sudo salt “web1” state.sls apache,apache.config,apache.restart , where web1 is the hostname of your minion)
Here we can see that there is a change that needs to be updated for the apache configuration file.
To apply the salt formula just remove the option:
sudo salt “web1” state.sls apache,apache.config,apache.restart .
Opinions expressed by DZone contributors are their own.