After 4 posts about Puppet, I think you should know how Puppet works and how we configure a basic server with directory creation, package installation, … But there are many complicated tasks waiting for you in the System Admin life :).
As you know, there are many System Admins like us in the world and they are very great by creating and sharing puppet modules for the community.
You can find more many modules in Puppet Forge - Repository of Modules . At the time I write this post, there are 3,963 modules in many fields and sections created and shared by the community.
In this Post, I will instruct you how to use module NGINX to configure a Web Server with multiple Virtual Hosts (Server Blocks) hosting static content .
TIPS
In Puppet Forge, put your query search in the Search form, there may be many modules in the result set.
I follow the below rules to find best module for me : (step by step )
- Review the module with the icon which means well-tested with Puppet.
- Review the module with the icon which means well-written and actively maintained.
- Review the module with highest rating point.
- Review the module with highest downloaded time.
- Review all modules in the result set to find the best module for you .
Note : Please answer the survey for the module to help the arthors to improve their module and the community to find the right module.
Okay, let’s start with our basic tasks :
- Create directories :
- /var/www/html/web1 owned by user web1 with mode: 755
- /var/www/html/web2 owned by user web2 with mode: 755
- /var/www/html/web3 owned by user web3 with mode: 755
- Create files :
- /var/www/html/web1/index.html owned by user web1 with mode: 755 and content : “WEB 1 Index”
- /var/www/html/web2/index.html owned by user web2 with mode: 755 and content : “WEB 2 Index”
- /var/www/html/web3/index.html owned by user web3 with mode: 755 and content : “WEB 3 Index”
- Configure Nginx Virtual Hosts ( Server Blocks )
- web1.summernguyen.net with document root /var/www/html/web1
- web2.summernguyen.net with document root /var/www/html/web2
- web3.summernguyen.net with document root /var/www/html/web3
Let’s have a look at the tasks and analyze : what is the order of theses tasks ? What task shoud be executed first ? what’s next ? what’s end ? (See Relationships and Ordering)
Here is a order of tasks I recommend :
- Ensure User web1 , web2 , web3 is present.
- Ensure directory /var/www/html is present (you know, with mode : 755 ) .
- Ensure directories /var/www/html/web1 , /var/www/html/web2 , /var/www/html/web3 is present with righ owner. This requires both task 1 and 2 completed before executing.
- Install Nginx
- Configure 3 Nginx Virtual Hosts . This requires all of the above tasks completed before executing.
Because we are using module NGINX, so we will complete task 4 and 5 by using this module
Let’s start
1. on Puppet Master - Install Module NGINX
Puppet will install Nginx Module and it’s dependent modules to /etc/puppet/modules
Before writing manifest, please have a look at the module instruction written by the author HERE
2. on Puppet Master, Write manifest for the Server puppet-agent.summernguyen.net by creating /etc/puppet/manifests/sites.pp
3. on Puppet Agent - Apply the manifest
Run the command :
Well, you can check if it works by yourself.
Real Life Scenario
Imagine that you have a cluster consist of 10 Servers with this simple configuration.
If you do all the Server by Bash shell, I think it takes you about more than 1 hour.
But, it takes me only 5 minutes to write the manifest and 1 hour to write this whole post. Adding new Server is just copying and pasting.
There are many modules fit your need, find it by yourself or write a module and share to the community.
Hope you will love this post.
Previous Topic : PUPPET AUTOMATION SERIES - PART 4 - BEGINNERS CONFIGURATION GUIDE
Next Topic : PUPPET AUTOMATION SERIES - PART 6 - TROUBLESHOOTING