Puppet by examples

5 January 2015

Today I spent most of the day collecting various examples concerning puppet. The goal I have in mind is to have a single place to test all the Puppet stuff.

##1. Introduction

Puppet is a well-known software configuration utility. I use it to prepare Vagrant boxes. It can be seen as an abstraction layer, that helps one to define resources in a platform independent way.

A resource can be almost anything that you deal with when you set up a new server or reconfigure an existing one. It can be:

If you don’t know any software configuration solution Puppet is definitely worth trying.

Chef and Ansible are the most well known alternatives to Puppet. For more comprehensive list refer to Comparison of open-source configuration management software Wikipedia entry.

##2. First step: resources

The first step to master Puppet is to get acquainted with resources.

The complete documentation for resources is available on Puppet’s site

##3. How to use the examples?

The examples I prepared are mostly trivial and self documented. To run them, one by one, create a local clone:

$ git clone git@github.com:by-examples/puppet-by-examples.git
$ cd puppet-by-examples

Then you need to boot the VM. You can change the system within puppet-by-examples/Vagrantfile:

The instruction that follows was written for Ubuntu 14.04 (this is the default setting).

Run:

# Host OS
$ vagrant up
$ vagrant ssh

Once in guest, change the current directory to /vagrant:

# Guest OS
$ cd /vagrant

Now, you can run the Puppet examples that I have prepared.

The command:

$ puppet apply 01-resources/notify/notify-1.pp

will execute the example notify-1.pp.

To learn basics of Puppet:

##4. The Examples

I suggest you to work in the following order:

Some of the examples need root privileges and additional software.

Take a look at the example 01-resources/well-known-modules/puppetlabs-apache-1.pp. You will find in this example the following comment:

# Ubuntu
#   sudo puppet module install puppetlabs-apache --version 1.2.0
#   sudo puppet apply puppetlabs-apache-1.pp
#   sudo apt-get install lynx-cur -y
#   lynx by-examples.lh

It means, that in order to run the example in Ubuntu, you have to execute the following commands:

# Guest OS
$ sudo puppet module install puppetlabs-apache --version 1.2.0
$ sudo puppet apply puppetlabs-apache-1.pp
$ sudo apt-get install lynx-cur -y
$ lynx by-examples.lh

The command:

$ sudo puppet apply puppetlabs-apache-1.pp

will work only in 01-resources/well-known-modules/ directory. You have to proceed it with:

cd 01-resources/well-known-modules/

##5. The Examples

You will find the source code of the example on GitHub.

##6. Reading list

Fork me on GitHub