Use Salt States to Create LAMP Stack and Fail2ban Across Salt minions.
Updated by Linode
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.
/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
From step one directly above, a file for the
lamplisting is needed. Create a
/etc/salt/base/lamp.slsfile and add the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
apache2: # ID declaration pkg: # state declaration - installed # function declaration mysql-server: pkg: - installed php5: pkg: - installed php-pear: pkg: - installed php5-mysql: pkg: - installed
The above file defines an extremely simple Salt State using the pkg State module. State modules can be formatted a number of ways. The above text uses only an ID declaration, a state declaration, and the function declaration.
This Salt State ensures that a LAMP stack is installed across Minions.
From step one above, a file for the
extraslisting is needed. Create a
/etc/salt/base/extras.slsfile and add the below syntax:
1 2 3
fail2ban: pkg: - installed
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
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. To learn how to configure the LAMP Stack, try the Salt States for Configuration of Apache, MySQL, and PHP (LAMP) guide.
This guide is published under a CC BY-ND 4.0 license.