Puppet Tutorial PDF
Puppet Tutorial PDF
This tutorial will help in understanding the building blocks of Puppet and how it works in
an infrastructure environment. All the examples and code snippets used in this tutorial are
tested. The working code snippets can be simply used in any Puppet setup by changing
the current defined names and variables.
Audience
This tutorial has been prepared for those who want to understand the features and
functionality of Puppet and how it can help in reducing the complexity of managing an
infrastructure.
After completing this tutorial one would gain moderate level understanding of Puppet and
its workflow. It will also give you a fair idea on how to configure Puppet in a preconfigured
infrastructure and use it for automation.
Prerequisites
We assume anyone who wants to understand and learn Puppet should have an
understanding of the system administration, infrastructure, and network protocol
communication. To automate the infrastructure provisioning, one should have a command
over basic Ruby script writing and the underlying system where one wants to use Puppet.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@tutorialspoint.com
i
Puppet
Table of Contents
About the Tutorial ............................................................................................................................................ i
Audience ........................................................................................................................................................... i
Prerequisites ..................................................................................................................................................... i
Copyright & Disclaimer ..................................................................................................................................... i
Table of Contents ............................................................................................................................................ ii
ii
Puppet
iii
Puppet
iv
Puppet
Basic Puppet
1
Puppet
1. Puppet ─ Overview
Puppet follows client-server model, where one machine in any cluster acts as client known
as puppet master and the other acts as server known as slave on nodes. Puppet has the
capability to manage any system from scratch, starting from initial configuration till end-
of-life of any particular machine.
Idempotency
Puppet supports Idempotency which makes it unique. Similar to Chef, in Puppet, one can
safely run the same set of configuration multiple times on the same machine. In this flow,
Puppet checks for the current status of the target machine and will only make changes
when there is any specific change in the configuration.
Idempotency helps in managing any particular machine throughout its lifecycle starting
from the creation of machine, configurational changes in the machine, till the end-of-life.
Puppet Idempotency feature is very helpful in keeping the machine updated for years
rather than rebuilding the same machine multiple times, when there is any configurational
change.
Cross-platform
In Puppet, with the help of Resource Abstraction Layer (RAL) which uses Puppet resources,
one can target the specified configuration of system without worrying about the
implementation details and how the configuration command will work inside the system,
which are defined in the underlying configuration file.
2
Puppet
Puppet ─ Workflow
Puppet uses the following workflow to apply configuration on the system.
In Puppet, the first thing what the Puppet master does is to collect the details of
the target machine. Using the factor which is present on all Puppet nodes (similar
to Ohai in Chef) it gets all the machine level configuration details. These details are
collected and sent back to the Puppet master.
Then the puppet master compares the retrieved configuration with defined
configuration details, and with the defined configuration it creates a catalog and
sends it to the targeted Puppet agents.
The Puppet agent then applies those configurations to get the system into a desired
state.
Finally, once one has the target node in a desired state, it sends a report back to
the Puppet master, which helps the Puppet master in understanding where the
current state of the system is, as defined in the catalog.
3
Puppet
Puppet Resources
Puppet resources are the key components for modeling any particular machine. These
resources have their own implementation model. Puppet uses the same model to get any
particular resource in the desired state.
Providers
Providers are basically fulfillers of any particular resource used in Puppet. For example,
the package type ‘apt-get’ and ‘yum’ both are valid for package management. Sometimes,
more than one provider would be available on a particular platform. Though each platform
always have a default provider.
Manifest
Manifest is a collection of resources which are coupled inside the function or classes to
configure any target system. They contain a set of Ruby code in order to configure a
system.
4
Puppet
Modules
Module is the key building block of Puppet, which can be defined as a collection of
resources, files, templates, etc. They can be easily distributed among different kinds of
OS being defined that they are of the same flavor. As they can be easily distributed, one
module can be used multiple times with the same configuration.
Templates
Templates use Ruby expressions to define the customized content and variable input. They
are used to develop custom content. Templates are defined in manifests and are copied
to a location on the system. For example, if one wants to define httpd with a customizable
port, then it can be done using the following expression.
The httpd_port variable in this case is defined in the manifest that references this template.
Static Files
Static files can be defined as a general file which are sometimes required to perform
specific tasks. They can be simply copied from one location to another using Puppet. All
static files are located inside the files directory of any module. Any manipulation of the file
in a manifest is done using the file resource.
5
Puppet
2. Puppet ─ Architecture
Puppet Master
Puppet Master is the key mechanism which handles all the configuration related stuff. It
applies the configuration to nodes using the Puppet agent.
Puppet Agent
Puppet Agents are the actual working machines which are managed by the Puppet master.
They have the Puppet agent daemon service running inside them.
Config Repository
This is the repo where all nodes and server-related configurations are saved and pulled
when required.
6
Puppet
Facts
Facts are the details related to the node or the master machine, which are basically used
for analyzing the current status of any node. On the basis of facts, changes are done on
any target machine. There are pre-defined and custom facts in Puppet.
Catalog
All the manifest files or configuration which are written in Puppet are first converted to a
compiled format called catalog and later those catalogs are applied on the target machine.
7
Puppet
3. Puppet ─ Installation
Puppet works on the client server architecture, wherein we call the server as the Puppet
master and the client as the Puppet node. This setup is achieved by installing Puppet on
both the client and well as on all the server machines.
For most of the platforms, Puppet can be installed via the package manager of choice.
However, for few platforms it can be done by installing the tarball or RubyGems.
Prerequisites
Factor is the only pre-requisite that does not come along with the standard package edition
of Puppet. This is similar to Ohai which is present in Chef.
Standard OS Library
We need to have standard set of library of any underlying OS. Remaining all the system
comes along with Ruby 1.8.2 + versions. Following is the list of library items, which an OS
should consist of.
base64
cgi
digest/md5
etc
fileutils
ipaddr
openssl
strscan
syslog
uri
webrick
webrick/https
xmlrpc
Facter Installation
As discussed, the facter does not come along with the standard edition of Ruby. So, in
order to get the facter in the target system one needs to install it manually from the source
as the facter library is a pre-requisite of Puppet.
This package is available for multiple platforms however just to be on the safer side it can
be installed using tarball, which helps in getting the latest version.
8
Puppet
First, download the tarball from the official site of Puppet using the wget utility.
Next, un-tar the tar file. Get inside the untarred directory using the CD command. Finally,
install the facter using install.rb file present inside the facter directory.
# Installing Puppet
$ wget http://puppetlabs.com/downloads/gems/puppet-0.25.1.gem
$ sudo gem install puppet-0.25.1.gem
9
Puppet
4. Puppet ─ Configuration
Once we have Puppet installed on the system, the next step is to configure it to perform
certain initial operations.
Configuration File
The main configuration file for Puppet is etc/puppet/puppet.conf. All the configuration
files get created in a package-based configuration of Puppet. Most of the configuration
which is required to configure Puppet is kept in these files and once the Puppet run takes
place, it picks up those configurations automatically. However, for some specific tasks such
as configuring a web server or an external Certificate Authority (CA), Puppet has separate
configuration for files and settings.
Server configuration files are located in conf.d directory which is also known as the Puppet
master. These files are by default located under
/etc/puppetlabs/puppetserver/conf.d path. These config files are in HOCON format,
which keeps the basic structure of JSON but it is more readable. When the Puppet startup
takes place it picks up all .cong files from conf.d directory and uses them for making any
configurational changes. Any changes in these files only takes place when the server is
restarted.
There are different configuration files in Puppet which are specific to each component in
Puppet.
10
Puppet
Puppet.conf
Puppet.conf file is Puppet’s main configuration file. Puppet uses the same configuration file
to configure all the required Puppet command and services. All Puppet related settings
such as the definition of Puppet master, Puppet agent, Puppet apply and certificates are
defined in this file. Puppet can refer them as per requirement.
The config file resembles a standard ini file wherein the settings can go into the specific
application section of the main section.
[master]
dns_alt_names = MasterSrv,brcleprod01.vipin.com,puppet,puppet.test.com
reports = puppetdb
storeconfigs_backend = puppetdb
storeconfigs = true
environment_timeout = unlimited
Detail Overview
In Puppet configuration, the file which is going to be used has multiple configuration
sections wherein each section has different kinds of multiple number of settings.
11
Puppet
Config Section
Puppet configuration file mainly consists of the following config sections.
Main: This is known as the global section which is used by all the commands and
services in Puppet. One defines the default values in the main section which can
be overridden by any section present in puppet.conf file.
Master: This section is referred by Puppet master service and Puppet cert
command.
User: It is mostly used by Puppet apply command as well as many of the less
common commands.
[main]
certname =PuppetTestmaster1.example.com
Comment Lines
In Puppet, any comment line starts with (#) sign. This may intend with any amount of
space. We can have a partial comment as well within the same line.
# This is a comment.
Testing= true #this is also a comment in same line
Settings Lines
Settings line must consist of -
Setting Variables
In most of the cases, the value of settings will be a single word but in some special cases,
there are few special values.
12
Puppet
Paths
In configuration file settings, take a list of directories. While defining these directories, one
should keep in mind that they should be separated by the system path separator character,
which is (:) in *nix platforms and semicolons (;) on Windows.
# *nix version:
environmentpath = $codedir/special_environments:$codedir/environments
# Windows version:
environmentpath =
$codedir/environments;C:\ProgramData\PuppetLabs\code\environment
In the definition, the file directory which is listed first is scanned and then later moves to
the other directory in the list, if it doesn’t find one.
In the above code, the allowed hash are owner, group, and mode. There are only two valid
values of the owner and group keys.
13
Puppet
14