Use Salt States to Create LAMP Stack and Fail2ban Across Salt minions
Updated by Edward Angert
Salt States can install and define a server setup on other servers. This tutorial demonstrates the use of Salt States to create a LAMP stack across all Salt Minions.
Configure the Salt Master
Before configuration, install a Salt Master and Salt Minions with the Linode Install Salt guide. This tutorial is written for Debian 8, but can easily be adjusted for other Linux Distributions.
/etc/salt/masterfile. Then search for file_roots, optionally read the surrounding “File Server settings” section, and edit the following:
1 2 3 4
# Example: file_roots: base: - /etc/salt/base
Copy the above text exactly to ensure the proper two-space nesting of YAML formatting. Also notice the other possible Minion States listed under the example base file root.
Create the newly listed file root directory:
The Salt Master’s configuration file has now been adjusted for a new base directory. The base directory typically contains the SLS files that create a tree like organization for Salt States pertaining to that directory. Additional directories, similar to the base directory, could be created with additional SLS files for different Salt State categories.
Create the Top and Additional SLS Files
The top file creates the top level organization for Salt States and Minions within the directory. Other SLS files typically correspond to the top file listings.
As mentioned in the note above, each of these configuration files requires specific spacing. To ensure consistency, copy the examples below, including
/etc/salt/base/top.slsfile and add the following. Again, ensure exact formatting for the YAML two space nesting.
1 2 3 4
base: '*': - lamp - extras
/etc/salt/base/lamp.slsfile referred to in Step 1, and add the following:
1 2 3 4 5 6 7
lamp-stack: pkg.installed: - pkgs: - mysql-server - php5 - php-pear - php5-mysql
This file defines a simple Salt State using the pkg State Module. This Salt State ensures that a LAMP stack is installed across Minions.
The second bullet listed in
extrasfile which will list and install additional software. Create a
/etc/salt/base/extras.slsfile and add the following:
Restart the Salt Master:
systemctl restart salt-master
Create the Salt State on the Minions
To install the packages listed above and create a Salt State, run:
salt '*' state.highstate
This process will take a few minutes. If successful, a report will be displayed with a summary similar to the following:
1 2 3 4 5 6
Summary ------------ Succeeded: 2 (changed=2) Failed: 0 ------------ Total states run: 2
For additional verification that the services are active on the minion, run:
salt '*' cmd.run "service --status-all | grep 'apache2\|mysql\|fail2ban'"
A LAMP stack and Fail2ban Salt State has been created on all listed Salt Minions. For more information on how to configure the LAMP Stack, refer to the Salt States for Configuration of Apache, MySQL, and PHP (LAMP) guide.
This guide is published under a CC BY-ND 4.0 license.