Book Image

Puppet for Containerization

By : Scott Coulton
Book Image

Puppet for Containerization

By: Scott Coulton

Overview of this book

This book teaches you how to take advantage of the new benefits of containerization systems such as Docker, Kubernetes, Docker Swarm, and Docker UCP, without losing the panoptical power of proper configuration management. You will learn how to integrate your containerized applications and modules with your Puppet workflow. You will also understand how to manage, monitor, and orchestrate hosts to keep deployed containers running seamlessly. With the help of this book, you can efficiently automate and document with containers, as a part of your system. The book will also cover use cases of deploying Puppet within a containerized environment.
Table of Contents (16 chapters)

Installing Vagrant


You may ask, why are we using Vagrant for our development environment?

Vagrant is a must-have for Puppet development. The idea that you can spin up environments for development locally in minutes was a revolution in Vagrant's early releases. The product has now grown in leaps and bounds, with multiple provisioners such as Chef and Salt. Paired with multiple virtualization backends such as VirtualBox, VMware Workstation/Fusion, KVM, and we are going to use VirtualBox and Puppet as your provisioner.

The installation

Let's install Vagrant. Firstly, we will need our virtualization backend, so let's download and install VirtualBox. At the time of writing, we use VirtualBox 5.0.10 r104061. If that's outdated by the time you read this book, just grab the latest version.

You can download VirtualBox from https://www.virtualbox.org/wiki/Downloads. Choose the version for your OS, as shown in the following screenshot:

Once the package is downloaded, follow the given installation process for your OS.

VirtualBox

Follow these steps to install Vagrant on Mac OSX:

  1. Go to your Downloads folder and double-click on VirtualBox.xxx.xxx.dmg. The following installation box will pop up:

  2. Then, click on VirtualBox.pkg. Move on to the next step, as shown in the following screenshot:

    The installer will then check whether the software is compatible with the Mac OSX version.

  3. After this, click on Continue. Once the check is successful, we can move on to the next step:

  4. We then choose the default location for the installation and click on Install.

  5. Then, enter your admin password and click on Install Software:

The installation is now complete. The following screenshot shows what the screen looks like after completing the installation:

Now that we have the virtualization backend, we can install Vagrant:

Note

At the time of writing this book, we are going to use Vagrant 1.7.4; if that is no longer the latest version, please grab the latest one. You can find this version of Vagrant at https://www.vagrantup.com/downloads.html. Again, download the installation package for your OS.

Vagrant

Here, we are just going to complete a standard installation. Follow these steps to do so:

  1. Go to the folder in which you downloaded vagrant.1.7.4.dmg and double-click on the installer. You will then get the following pop up:

  2. Double-click on vagrant.pkg.

  3. Then, in the next dialogue box, click on Continue:

  4. Then, click on the Install button:

  5. Enter your admin password in the given field:

  6. Once the installation is complete, open your terminal application. In the command prompt, type vagrant. After this, you should see the following screenshot:

Vagrantfile

Now that we have a fully working Vagrant environment, we can start with and look at how Vagrant works and how we are going to provision our machines. As this book is not about Vagrant, we won't be writing a Vagrantfile from scratch. Instead, I have created a Vagrantfile that we will be using throughout the book:

Note

You can download or Git pull the repo from https://github.com/scotty-c/vagrant-template.

Let's look at the Vagrantfile construct:

As you can see from the preceding screenshot, the Vagrantfile is actually a Ruby file. As it is Ruby, it opens up a world of opportunities for us to make our code elegant and efficient. So, in this Vagrantfile, we have extracted all the low-level configurations and replaced them with a few parameters. Why are we doing this? The reason is to split up our logic from our configuration and also iterate our configuration in order to stop replication of our code. So, where is all the configuration stored? The answer is in the servers.yaml file. This is where we set the vagrant box that we want to deploy, the number of CPUs for the box, the internal network's IP, the hostname, the forwarded ports between the guest and host, and the RAM and shell provider for bash commands that we need to get the environment ready for Puppet to run, for example, downloading modules and their dependencies from the Puppet Forge:

The benefit of this approach is also that any developer using a Vagrantfile does not need to actually modify the logic in the Vagrantfile. They only need to update the configuration in servers.yaml. As we go through the book, we will work with the other files in the repository, such as Puppetfile, hieradata, and manifests. Now that we have set up our Vagrant environment, let's look at how to get our Puppet modules from the Puppet Forge.