Getting ready for Puppet
Although Puppet is inherently cross-platform and works with many different operating systems, for the purposes of this book I'm going to focus on just one operating system, the Ubuntu 16.04 LTS distribution of Linux, and the most recent version of Puppet, Puppet 4. However, all the examples in the book should work on any recent operating system or Puppet version with only minor changes.
You will probably find that the best way to read this book is to follow along with the examples using a Linux machine of your own. It doesn't matter whether this is a physical server, desktop or laptop, cloud instance, or a virtual machine (VM). I'm going to use the popular Vagrant software to run a virtual machine on my own computer, and you can do the same. The public GitHub repository for this book contains a Vagrantfile which you can use to get up and running with Puppet in just a few steps.
Installing Git and downloading the repository
To get a copy of the repository that accompanies this book, follow these steps:
- Browse to https://git-scm.com/downloads.
- Download and install the right version of Git for your operating system.
- Run the following command:
git clone https://github.com/bitfield /puppet-beginners-guide.git
Installing Virtualbox and Vagrant
If you already have a Linux machine or cloud server you'd like to use for working through the examples, skip this section and move on to Installing Puppet. If you'd like to use Virtualbox and Vagrant to run a local VM on your computer to use with the examples, follow these instructions:
- Browse to https://www.virtualbox.org/.
- Download and install the right version of Virtualbox for your operating system.
- Browse to https://www.vagrantup.com/downloads.html.
- Select the right version of Vagrant for your operating system: OS X, Windows, and so on.
- Follow the instructions to install the software.
Running your Vagrant VM
Once you have installed Vagrant, you can start the Puppet Beginner's Guide virtual machine:
- Run the following commands:
cd puppet-beginners-guide vagrant plugin install vagrant-vbguest vagrant up
- Vagrant will begin downloading the base box, which is an Ubuntu 16.04 image pre-installed with Puppet. This may take a while, but once the download is complete, the virtual machine will start.
- Connect to the VM with the following command:
vagrant ssh
- You now have a command line shell on the VM. To make sure you have the latest version of Puppet installed, run the following commands (answer
y
to any prompts):curl https://apt.puppetlabs.com/DEB-GPG-KEY-puppet |sudo apt-key add
sudo apt-get update sudo apt-get install -y puppetlabs-release-pc1 sudo apt-get install -y puppet-agent
- Check that Puppet is installed and working (you may get a different version number, which is fine):
sudo /opt/puppetlabs/bin/puppet --version 4.10.1
Tip
If you're using Windows, you may need to install the PuTTY software to connect to your VM. There is some helpful advice about using Vagrant on Windows at http://tech.osteel.me/posts/2015/01/25/how-to-use-vagrant-on-windows.html.
Alternative Vagrant VMs
The Vagrant configuration file (known as a Vagrantfile) in the example repository for this book specifies a particular Vagrant box, or downloadable machine image. If this box is no longer available, for whatever reason, you may see an error on running the vagrant up
command, like the following:
The box 'puppetlabs/ubuntu-16.04-64-puppet' could not be found or could not be accessed in the remote catalog.
If you get this error, browse to the following URL to see the available Puppet Vagrant boxes:
https://atlas.hashicorp.com/puppetlabs/Look for Ubuntu images ending in -puppet
(these have Puppet pre-installed). For example, puppetlabs/ubuntu-16.04-64-puppet
is an Ubuntu 16.04 image for 64-bit systems with Puppet pre-installed. Find the latest available such image and edit the Vagrantfile in the puppet-beginners-guide
directory to change the config.vm.box
setting appropriately:
config.vm.box = "puppetlabs/ubuntu-16.04-64-puppet"
Then try running the vagrant up
command again.
Adding Puppet to your path
We need to perform one more step which will make it easier for us to run Puppet on the node without having to specify the full path each time. Run the following command:
sudo visudo
An editor will start with the contents of the /etc/sudoers
file. Look for the following line:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Add :/opt/puppetlabs/puppet/bin
to this set of paths, so that it reads:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/puppetlabs/puppet/bin"
Save the file and exit the editor. The system is now setup to find the puppet
executable without specifying the full path to it. To test this, run the following command:
sudo puppet —version
4.10.1
Troubleshooting Vagrant
If you have any problems running the VM, look for help on the Virtualbox or Vagrant websites. In particular, if you have an older machine, you may see a message like the following:
VT-x/AMD-V hardware acceleration is not available on your system. Your 64-bit guest will fail to detect a 64-bit CPU and will not be able to boot.
Your computer may have a BIOS setting to enable 64-bit hardware virtualization (depending on the manufacturer, the trade name for this is either
VT-x or
AMD-V). Enabling this feature may fix the problem. If not, you can try the 32-bit version of the Vagrant box instead. Edit the file named Vagrantfile
in the Git repository, and comment out the following line with a leading #
:
config.vm.box = "puppetlabs/ubuntu-16.04-64-puppet"
Uncomment the following line by removing the leading #
character:
# config.vm.box = "puppetlabs/ubuntu-16.04-32-puppet"
Now rerun the vagrant up
command.