Learn How Puppet Is Used To Define Infrastructure As Code

0
3297
How Puppet

How Puppet

When IT teams rely on old infrastructure management techniques such as manual configuration and creating scripts such a process is error prone and slow. Forward thinking organizations treat infrastructure like software and apply techniques used in software management in infrastructure management to speed up the infrastructure management process approaches such as version control, continuous integration and automated code testing. By applying the mentioned techniques you can modify your infrastructure quickly, with repeatability, with simplicity and in a more safe and reliable way. In this article, our objective is to help you understand how you can use Puppet to manage your infrastructure.

Puppet is a tool developed using Ruby and offered as an open source or enterprise version. Each of the two versions has different capabilities. For a comprehensive discussion of the capabilities of each version look at this comparison. https://puppet.com/product/puppet-enterprise-and-open-source-puppet. To manage a few servers, the open source version is adequate, but when you have a large number of servers to manage the enterprise version is better.

Puppet is made up of three components which include a declarative language, a client and server, and a library. You use the declarative language for expression of configuration set up. The client and server enable distribution of Puppet. To realize the configuration you express using the declarative language you rely on the library.

Puppet functions as a client/server set up where all clients communicate to a single or multiple servers. At a regular interval which is by default set to 30 minutes every client communicates with the server and gets up to date configurations to eliminate the possibility of being out of sync with the configuration.

To centrally manage configurations you place a Puppet Agent on every server that needs configuration management. After creating the puppet agents, which are also referred to as nodes, we will assign one server to act as the master. The communication between each agent and master is secured through SSL.

Before we can begin working on any installation there are some set up decisions that we need to make. Puppet can either be run in standalone mode or in a client/server which can also be referred to agent/master mode. In a standalone mode, you place complete configuration on each server and the server maintains its catalog. In the agent/master mode, a master is in control and agents communicate with the master to get configuration information. A comprehensive discussion of the two modes is available here https://docs.puppet.com/puppet/latest/architecture.html to help you make a decision.

If you decide the agent/master mode is appropriate for you, you need to assign one server to act as the Puppet master and host the PuppetDB if you would like to use it. In an agent/master set up, you should install Puppet, on master and PuppetDB servers before setting up any agents.

Other set up pre-requisites that you need to consider are system requirements, network configuration and time accuracy on Puppet master.

Communication between the master and its nodes using DNS. DNS itself is a broad subject that we will not let distract our discussion of Puppet. To simplify networking, we will edit /etc/hosts file on each machine and add the Puppet master IP address.

We need to set up the server before setting up the nodes. The first step in Puppet server installation process is to enable the package repositories. Setting up the Puppet repository varies depending on the operating system. The different ways of setting up the repository are explained here . On ubuntu 16.04 xenial, the command below is used to set up the Puppet repository.

puppet rep setup
To install the Puppet server, use this command sudo apt-get install puppetserver
install puppet server
By default the Puppet server is allocated 2 GB of RAM. When you are interested in just exploring the server, you can reduce the memory allocation to 512 MB. On Debian systems such as ubuntu to change the memory allocation, we edit the init config file located in this directory /etc/default/puppetserver. Edit the configuration file so that it appears as shown below, to edit the file you will need elevated permissions.
edit puppet
After installation is complete, we can use this command service puppetserver start to start the service.

After configuring the master, we can move on to installing the agents. To install an agent, use the command below.

install agent
To start the puppet service, we use the command below

stert service
When the agent runs for the first time it will submit a certificate signing request to the certificate authority, which is the Puppet master. To check if there is any request pending, we run the command below on the Puppet master

If you find any request you can sign it using the command below by substituting the name of the request. The agent can then communicate with the server to request configuration information

In the previous sections, we focused on demonstrating how to set up Puppet. In the next section, we will demonstrate how to write provisioning code.

There are several concepts that are important when writing Puppet code. A resource is used to describe system status such as user, file or package existence. To get a list of all resources available by default, use the command below.

Manifests are the Puppet programs that contain code and they have a .pp file extension. In Puppet, making reusable and readable is done through classes.

Let us create a manifest and add the code chunk shown below, save and close the file.

sample
To execute our manifest, we use the command below

final
In this tutorial, we introduced the benefits of using tools for infrastructure management. We demonstrated how to set up Puppet in an agent/master architecture. We reviewed important concepts in Puppet code writing. Finally, we demonstrated how to write Puppet code.

LEAVE A REPLY

Please enter your comment!
Please enter your name here