Puppet is an open source configuration management system that can be used for a wide variety of applications, from automation to update installation. It is written in Ruby and specially designed to manage the configuration of Unix and Windows like operating systems. You can easily deploy and manage a single server or thousands of physical and virtual servers from a central location.
Puppet can be used in a client-server architecture or standalone architecture. In a client-server architecture, the server is known as a master and client known as an agent. Puppet is available in two versions, Enterprise and Open source. Both of them support many Linux distributions and Windows. Puppet helps system administrator by cutting down on time spent on repetitive tasks, and by allowing them to focus on the projects that deliver greater business value.
• Puppet supports Idempotency which makes it easier to run the same set of configurations multiple times on the same machine.
• Eliminates the need for duplicated tasks for everyone solving the same problem.
• Every task is written in native code and can be shared easily.
• Allows us to make repeatable changes automatically.
• Adds extra functionality by adding extensions when required.
This guide will help you through the steps for installing and configuring open source Puppet in Client-Server architecture on Ubuntu 16.04 server, with Alibaba Cloud Elastic Compute Service (ECS) instances.
• A fresh Alibaba Cloud ECS instance for Puppet Master with Ubuntu 16.04 installed.
• A fresh Alibaba Cloud ECS instance for Puppet Agent with Ubuntu 16.04 installed.
• A static IP address 192.168.0.103 is configured on Puppet Master.
• A static IP address 192.168.0.104 is configured on Puppet Agent.
• Minimum 4 GB Memory and Dual-Core CPU is required for Puppet Master.
• Non-root user with sudo privileges is configured on both instances.
Before starting, you will need to configure /etc/hosts and /etc/hostname file on Server node and agent node, so they can able to communicate with each other.
On the Server node, open /etc/hosts and /etc/hostname file and make the following changes:
<code>sudo nano /etc/hosts</code>
Add the following line at the end of the file:
<code>192.168.0.103 puppet-server</code>
<code>sudo nano /etc/hostname</code>
Change the file as shown below:
<code>puppet-server</code>
Save and close the file when you are finished.
On the Agent node, open /etc/hosts and /etc/hostname file and make the following changes:
<code>puppet-agent</code>
Puppet server is not available in Ubuntu 16.04 default repository. So you will need to add Puppet Lab repository on both Master and Agent node.
On each node, run the following command to download and install Puppet repository:
Next, install Puppet server package on Master node with the following command:
<code>sudo apt-get install puppetserver -y</code>
After installing the Puppet server, you will need to configure the memory allocation. You are recommended to customize the memory usage depends on how much memory your master node has. You can do this by editing /etc/default/puppetserver file:
<code>sudo nano /etc/default/puppetserver</code>
Change the lines as per your server capacity:
From
<code>JAVA_ARGS="-Xms2g -Xmx2g -XX:MaxPermSize=256m"</code>
To
<code>JAVA_ARGS="-Xms512m -Xmx512m"</code>
Save and close the file, then start Puppet server and enable it to start on boot time with the following command:
You can check the status of the Puppet server using the following command:
<code>sudo systemctl status puppetserver</code>
If everything when fine you should see the following output:
Now, your Puppet server is up and running. It's time to install Puppet agent on Agent node.
Before installing Puppet agent, make sure you have installed Puppet Lab repository on Agent node. Next, install Puppet agent by just running the following command:
<code>sudo apt-get install puppet-agent -y</code>
Once Puppet agent is installed, you will need to edit the puppet configuration file and set puppet master information.
You can do this with the following command:
<code>sudo nano /etc/puppetlabs/puppet/puppet.conf</code>
Add the following lines:
Save and close the file, then start Puppet agent service and enable it to start on boot time with the following command:
When the Puppet runs Agent node first time, it sends a certificate signing request to the Puppet server. In Client-Server architecture, Puppet master server must approve a certificate request for each Agent node to control the Agent node.
On Puppet server, list all unsigned certificate requests with the following command:
<code>sudo /opt/puppetlabs/bin/puppet cert list</code>
You should see the one request with your agent node's hostname:
<code>"puppet-agent" (SHA256) 7C:28:E8:AF:09:23:55:19:AF:C1:EE:C3:66:F2:02:73:AD:7F:53:17:28:CE:B0:26:AE:C7:6C:67:16:05:6F:2E</code>
Next, sign a certificate request using the following command:
<code>sudo /opt/puppetlabs/bin/puppet cert sign puppet-agent</code>
You should see the following output:
The Puppet Master server is now able to communicate and control the Agent node. If you want to sign certificate request of multiple nodes at once, then run the following command:
<code>sudo /opt/puppetlabs/bin/puppet cert sign --all</code>
Once the Puppet master has signed your Puppet Agent certificate, run the following command on Puppet Agent node to test it:
<code>sudo /opt/puppetlabs/bin/puppet agent --test</code>
If everything is done correctly, you should see the following output:
Both Puppet Master and Agent node are now configured and are functional. It's time to verify Puppet.
To do so, create a manifest file to install Apache web server on Agent node. Manifest is a data file that contains client configurations. By default, manifest file is located at /etc/puppetlabs/code/environments/production/manifests/ directory.
Before proceeding to create a manifest file, you will need to install the puppetlabs-apache module.
On the Puppet master node, run the following command to install the puppetlabs-apache module:
<code>sudo /opt/puppetlabs/bin/puppet module install puppetlabs-apache</code>
Next, create a manifest file on the Puppet master with the following command:
<code>sudo nano /etc/puppetlabs/code/environments/production/manifests/site.pp</code>
The above configuration will install the Apache, configure a virtual host called localhost, listening on port 80, and with a document root /var/www/html on Agent node.
Now, on the Agent node, run the following command to retrieve all the configuration from manifest file:
If everything is successful, you should see the following output:
Congratulations! Apache is now installed and running on the Agent node.