Getting Started with Puppet - Hello World!

Posted by Alan Sharp-Paul

As there's a lot of interest out there in the various IT automation tools on offer I thought I'd do a series of blogs covering getting started on each. In particular I wanted to put them to the test regarding how simple it is to go from zero to "Hello World" *. This way I get to play the truly dumb user (not much of a stretch, I know), which is kinda fun too.

* Yes, I'm borrowing a programming concept here, the notion that printing "Hello World" to a screen is the simplest way to demonstrate basic functionality.

So, first up is Puppet. Let's see how we go.

1. To Google!

I Google Puppet Getting Started. First link was this one. Unfortunately it's a deprecated page for mcollective. Hmm, an inauspicious start.

2. Documentation

I see a Documentation link in the very top nav though. From there I drill into Puppet and finally to the Learning Puppet section. OK, this feels more promising.

3. Serverless Puppet

Part 1 in the learning series is for serverless Puppet. Sounds good to get me playing around. Hmm, 8 articles though and none of them seem to be a nice, easy getting started tutorial. I guess I have some reading to do. Here's my summary of the key stuff from those articles:

4. Learning about Resources and the RAL

Puppet calls configuration items (files, users, groups, packages, services etc) resources and the collection of them their Resource Abstraction Layer (RAL). Rather than code, resources are defined in json format. Here's an example resource definition for a user:

user { 'dave':
  ensure     => present,
  uid        => '507',
  gid        => 'admin',
  shell      => '/bin/zsh',
  home       => '/home/dave',
  managehome => true,
}

4. Learning about Manifests

Resources are combined within files (*.pp) called manifests which can then be applied to machines. OK, this is interesting. I've found an example manifest that looks like it will form the basis of my "Hello World" test (I make one small tweak to a file contents specification). All it does is create one file, one directory, an alias and also send some notifications:

file {'/tmp/test1':
  ensure  => present,
  content => "Hello World!",
}

file {'/tmp/test2':
  ensure => directory,
  mode   => 0644,
}

file {'/tmp/test3':
  ensure => link,
  target => '/tmp/test1',
}

notify {"I'm notifying you.":} # Whitespace is fungible, remember.
notify {"So am I!":}

There are 7 more articles (dependencies, variables, modules etc) but I'm lazy and they feel too advanced for what I'm trying to achieve so I'll skip them for now :)

5. Lemme at it!

Now, how do I run this thing? Ah, there's another section towards the bottom of the Learning Puppet page called Get Equipped. It wants me to make use of a pre-baked VM. That's handy but I really just want a "Hello World" test so I'm going to install on my Mac instead. Back to Google.

6. Installation
OK. Found the install details for Mac (info for other OS's is also on this page) here. Let's give it a go.

7. Download all the things!
So I need to download and install the most recent Facter, Hiera and Puppet packages which are found on this page. Making me choose is annoying. Anyway, I'll download and run facter-1.7.1, hiera-1.2.1 and puppet-3.2.1. I install in that order as instructed.

8. Configurationing
I'm told to go to the terminal and do some manual configuration. So:

Create the puppet group:

sudo puppet resource group puppet ensure=present

Create a puppet user:

sudo puppet resource user puppet ensure=present gid=puppet shell='/sbin/nologin'

I'll skip the daemon set up.

9. What did that do?

At this point I think I'll use UpGuard's scan and diff'ing functionality to compare my machine pre and post install. Oui, oui, c'est la bombe atomique! Check it:

Puppet Install Diff - UpGuard

I see that the following has been added:

Files
- /etc/facter.conf
- /etc/hiera.yml
- /etc/puppet/auth.conf
- /usr/bin/facter
- /usr/bin/hiera
- /usr/bin/puppet
Group
- puppet
User
- puppet

10. Make it tight

While I'm here I'll save those elements in a UpGuard package so I can go back and validate them at any time:

Puppet Validation - UpGuard

11. Post-install

I see a link Continue Reading Here and click it for post-install instructions.

It tells me that the conf file is stored here:

/etc/puppet/puppet.conf

Hmm, that's weird. I know it wasn't created because the scan didn't find it. I guess I need to create it. There's a specific link for Configuring Puppet but there are also basic instructions in the post-install section.

12. Standalone Nodes Config

OK, so the section "On Standalone Nodes" looks to be what I want. It tells me:

Settings for standalone puppet nodes should go in the [main] block of puppet.conf.

Puppet’s default settings are generally appropriate for standalone nodes. No additional configuration is necessary unless you intend to use centralized reporting or an external node classifier.

Now I'm a bit confused. I still don't know what goes in my puppet.conf file. I search around for an example of a default settings puppet.conf without any joy. You know what? I'm just going to try and apply my test manifest and see what happens. After all, this is starting to take longer than I'd wanted to spend on it. It's almost lunch!

13. Create and apply a Manifest

So I save the above manifest example as hello_world.pp and then run the following from the terminal, as specified in the same manifest article that gave me the example:

puppet apply hello_world.pp

Success!

Here's the output:

Notice: /Stage[main]//File[/tmp/puppet/test1]/ensure: created
Notice: /Stage[main]//File[/tmp/puppet/test3]/ensure: created
Notice: So am I!
Notice: /Stage[main]//Notify[So am I!]/message: defined 'message' as 'So am I!'
Notice: I'm notifying you.
Notice: /Stage[main]//Notify[I'm notifying you.]/message: defined 'message' as 'I'm notifying you.'
Notice: /Stage[main]//File[/tmp/puppet/test2]/ensure: created
Notice: Finished catalog run in 0.08 seconds

I check my tmp directory and I do indeed have a new file, test1, a new directory, test2 and an alias, test3 -> test1. test1 has the contents:

"Hello World!"

14. Wrapping Up

Well there you have it. Zero to Hello World! with Puppet. A few complaints with the process in that the documentation didn't flow very nicely, some things were hard to find and it wasn't at all clear that the config file was optional.

I'm sure Puppet would say that they're not targeting this type of use case but I think it's important. Some people don't have a lot of time to evaluate software so first impressions count. Seeing something in action quickly means a lot.

Hope you found this useful anyway. Next time, Chef!

Request a Free Demo

Topics: guardrail, getting started, puppet

UpGuard Customers