In this chapter, you will install the Puppet agent and its dependencies. We have deliberately chosen a Vagrant box that doesn’t have Puppet preinstalled, so that you can go through and learn the process. You can repeat these exact steps on any test or production node to install or upgrade Puppet.
Let’s get started by installing the Puppet Labs package repository.
Now we’ll install and enable a Puppet Labs Puppet Collection repository on your fresh new system. Our first step is to check what the latest Puppet Collection is. You can find this at “Using Puppet Collections” in the Puppet Labs online documents.
Get the URL for the Enterprise Linux 7 Collection and install that package as described in the documentation.
For EL/CentOS versions 6 and above, you can simply use yum install rather than rpm -ivh:
[vagrant@client~]$sudoyuminstall-y\http://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
This installs and enables a Puppet Collection package repository, which contains the Puppet 4 package. After it has finished installing, you can confirm it is enabled with the following command:
[vagrant@client~]$sudoyumrepolistLoadedplugins:fastestmirror...sniprepositorychecks...repoidreponamestatusbase/7/x86_64CentOS-7-Base9,363extras/7/x86_64CentOS-7-Extras451puppetlabs-pc1/x86_64PuppetLabsPC1Repositoryel7-x86_64128updates/7/x86_64CentOS-7-Updates2,146repolist:12,088
This shows you that there were 128 packages in the puppetlabs-pc1 repository (when this book was last updated).
The Puppet ecosystem contains many tightly related and dependent packages. Puppet, Facter, MCollective, and the Ruby interpreter are all tightly related dependencies. The Puppet agent, Puppet server, and PuppetDB are self-standing but interdependent applications.
Production Puppet environments have been struggling with several conflicting needs:
Puppet Labs has chosen to address these concerns with two related changes:
Now let’s go ahead and install the Puppet agent:
[vagrant@client~]$sudoyuminstall-ypuppet-agentLoadedplugins:fastestmirrorLoadingmirrorspeedsfromcachedhostfile*base:centos.sonn.com*extras:mirrors.loosefoot.com*updates:mirrors.sonic.netResolvingDependencies-->Runningtransactioncheck--->Packagepuppet-agent.x86_640:1.10.9-1.el7willbeinstalled-->FinishedDependencyResolution...sniplotsofoutput...RunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionInstalling:puppet-agent-1.10.9-1.el7.x86_641/1Verifying:puppet-agent-1.10.9-1.el7.x86_641/1Installed:puppet-agent.x86_640:1.10.9-1.el7Complete!
Guides for installing Puppet on other platforms can be found in Appendix A.
If you have installed previous versions of Puppet, you’re accustomed to seeing dependency packages installed along with Puppet. Puppet 4 uses an All In One (AIO) installer, where all dependencies are installed together with Puppet. You can view these in the new installation directory:
[vagrant@client ~]$ls -la /opt/puppetlabs/bin/ total 0 drwxr-xr-x2root root68Apr64:41 . drwxr-xr-x4root root29Apr64:41 .. lrwxrwxrwx1root root33Apr64:41 facter -> /opt/puppetlabs/puppet/bin/facter lrwxrwxrwx1root root32Apr64:41 hiera -> /opt/puppetlabs/puppet/bin/hiera lrwxrwxrwx1root root30Apr64:41 mco -> /opt/puppetlabs/puppet/bin/mco lrwxrwxrwx1root root33Apr64:41 puppet -> /opt/puppetlabs/puppet/bin/puppet
Unlike previous versions, the Puppet commands are not installed in /usr/bin, and won’t be available in your default path. This puppet-agent package adds the file /etc/profile.d/puppet-agent.sh, which will add /opt/puppetlabs/bin to your path. This file is automatically included by the Bash shell during initialization. Let’s use that now:
[vagrant@client~]$whichpuppet/usr/bin/which:nopuppetin(/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin)[vagrant@client~]$source/etc/profile.d/puppet-agent.sh[vagrant@client~]$whichpuppet/opt/puppetlabs/bin/puppet
$PATH in your shell configuration files, you must add source /etc/profile.d/puppet-agent.sh after that point to have the path added.Let’s review the other programs you see in this directory besides Puppet:
Facter is a program that evaluates a system and provides a number of facts about it. These facts include node-specific information (e.g., architecture, hostname, and IP address), in addition to custom information from plugins provided by Puppet modules. For a sneak preview, run the command facter right now and look at all the information it has.
We’ll be covering how to make use of Facter facts in Chapter 5, and how to create custom facts in Part II.
Hiera is a component we’ll use to load in the data used by Puppet manifests and modules. Hiera allows you to provide default values and then override or expand them through a customizable hierarchy. This may sound complex, but Hiera’s beauty and elegance comes from its simplicity.
You’ll learn how to use Hiera in Part II, and after its introduction, you will see Hiera used in every subsequent example in the book.
Marionette Collective, or MCollective, is an orchestration framework tightly integrated with Puppet.
You’ll learn how to use it in Part IV, where we’ll use the mco client to manipulate the Puppet agent.
If you have installed previous versions of Puppet, you’ll notice that the installation packages and the configuration file paths have all changed.
For Unix and Linux systems, the following changes have taken place:
puppet-agent packagegem are installed in /opt/puppetlabs/puppet, to avoid them being accidentally called by users.$confdir is now /etc/puppetlabs/puppet$ssldir directory is now $confdir/ssl$vardir for Puppet is now /opt/puppetlabs/puppet/cache/puppet agent and puppet apply. You can change this by setting $vardir in the Puppet config file.$rundir for Puppet agent is now /var/run/puppetlabsPuppet code and data has moved from $confdir to a new directory $codedir. This directory contains:
$environmentpath$basemodulepathOn Windows, very little has changed. The Puppet package has always been an AIO installer. The package now includes MCollective. Executables remain in the same location, and the MSI package still adds Puppet’s tools to the PATH. The $confdir and $rundir have not changed.
For review, the file locations are:
$confdirCOMMON_APPDATA defaults to C:\ProgramData\PuppetLabs\puppet\etc$codedir$vardir$rundirThroughout this book, you’ll edit files and make changes within the Puppet configuration directory. Normally, this would require you to type sudo every time you want to change a file.
I have found that most people prefer the following change to create an easier-to-use environment for learning (this command will make the vagrant user the owner of all files in that directory):
[vagrant@client~]$sudochown-Rvagrant/etc/puppetlabs
The remainder of this book assumes you have made this change. If you decide to continue using sudo, you’ll need to add it to any command involving files in /etc/puppetlabs.
[vagrant@client~]$sudochown-Rvagrant/etc/puppetlabs[vagrant@client~]$sudopuppetapply-e''Notice:Compiledcatalogforclient.example.cominenvironmentproductionNotice:Appliedcatalogin0.01seconds
Obviously you won’t be using the vagrant user in a production environment. However, it is not uncommon to see something like the following done to give write access to all members of a certain group:
[vagrant@client ~]$ sudo chgrp -R sysadmin /etc/puppetlabs [vagrant@client ~]$ sudo chmod -R g+w /etc/puppetlabs
One reason you may not want to change the ownership of this directory would be if your Puppet deployment was managed by continuous integration tools, and you want to ensure that everybody uses the tools. That won’t be a problem when using this book, and chown -R vagrant /etc/puppetlabs is highly recommended for the lessons here.
When you run Puppet with sudo, it uses the system-level configuration files, like so:
[vagrant@client~]$sudopuppetconfig|grepdirconfdir=/etc/puppetlabs/puppetcodedir=/etc/puppetlabs/codevardir=/opt/puppetlabs/puppet/cachelogdir=/var/log/puppetlabs/puppet...etc...
When you run Puppet without sudo, it will use paths in your home directory for configuration files. This can be useful when you are writing and testing small manifests:
[vagrant@client~]$puppetconfig|grepdirconfdir=/home/vagrant/.puppetlabs/etc/puppetcodedir=/home/vagrant/.puppetlabs/etc/codevardir=/home/vagrant/.puppetlabs/opt/puppet/cachelogdir=/home/vagrant/.puppetlabs/var/log...etc...
Most people don’t want to be constantly migrating changes back and forth between two different directory structures. There are two ways to resolve this dilemma:
sudo every time you run PuppetI much prefer the second approach, and I recommend it for daily use. For this reason, we have preinstalled the ~/.puppetlabs/etc/puppet/puppet.conf configuration file on all Vagrant configurations, which enables this for you. Check it out:
[vagrant@client~]$cat~/.puppetlabs/etc/puppet/puppet.conf# Allow "puppet hiera" and "puppet module" commands without sudo[main]logdest=consoleconfdir=/etc/puppetlabs/puppetcodedir=/etc/puppetlabs/code
If you don’t like this setup, you are welcome to remove this file. Just remember to use sudo with every Puppet command, or it will use a different configuration file than you expect.
On most systems, the sudo command resets the user search path to a list of known safe directories. Unfortunately, this does not include the Puppet directory. You can see the effect of this change with the following command:
[vagrant@clientvagrant]$env|grepPATHPATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/puppetlabs/bin:/home/vagrant/.local/bin:/home/vagrant/bin[vagrant@clientvagrant]$sudoenv|grepPATHPATH=/bin:/sbin:/bin:/usr/sbin:/usr/bin
If you want to run Puppet with sudo, you’ll need to add the /opt/puppetlabs/bin directory to sudo’s secure_path default. The following command will get the current secure_path from the sudoers file, and create a sudoers.d/ config extension that appends /opt/puppetlabs/bin:
$sudogrepsecure_path/etc/sudoers\|sed-e's#$#:/opt/puppetlabs/bin#'\|sudotee/etc/sudoers.d/puppet-securepathDefaultssecure_path=/sbin:/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin$sudoenv|grepPATHPATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin
During the course of this chapter, you did the following:
Best of all, none of this was done with magic helper scripts that hid the details from you. You can repeat these exact steps on any test or production node to install or upgrade Puppet.