Hello Puppet revisited – on Ubuntu 12.04 LTS

Learn “Hello Puppet World” in 5 minutes. Write one-liners & modules. Meet the configuration management system used by Google and Wikipedia.
Prequisites: command line, sudo and apt. You need Xubuntu 12.04 live CD (burn image). To use non-US keyboard: ‘setxkbmap fi’.
Update 2016: These instructions work on Ubuntu 14.04 LTS, too.

Install Puppet Agent

$ sudo apt-get update
$ sudo apt-get install puppet

Puppet One-Liner

$ puppet apply -e 'file { "/tmp/helloPuppet": content => "Hello Tero!\n" }'

It should say it created the file and that it’s done: “File[/tmp/helloPuppet]/ensure: defined content as… Finished catalog run”. If you want, you can look at your file with ‘ls /tmp/helloPuppet’ and ‘cat /tmp/helloPuppet’.
Congratulations, you’ve run your first puppet program.
If you want to play with puppet, try running the same command a couple of times. You’ll notice how it doesn’t do anything if file is already in place with the right contents.

Running a Puppet Module

When you create something with Puppet, you create a module. A module to configure Apache, a module to configure LibreOffice with Finnish support… Writing your fist module is easy.
All your puppet code goes to puppet folder.

$ mkdir puppet
$ cd puppet

Modules go to puppet/modules/. Each module must have at least one file and one directory: manifests/init.pp.

$ mkdir -p modules/hello/manifests/
$ nano modules/hello/manifests/init.pp

The code in module must be in a class named after the module. Contents of init.pp:

class hello {
        file { '/tmp/helloModule':
            content => "See you at TeroKarvinen.com!\n"
        }
}

You can run your module now

$ puppet apply --modulepath modules/ -e 'class {"hello":}'

On the first run, it creates your file “/Stage[main]/Hello/File[/tmp/helloModule]/ensure: defined content as…” and tell you it’s done. You can admire your file with ‘ls /tmp/helloModule’ and ‘cat /tmp/helloModule’.
Congratulations, you just wrote your first puppet module!

What next?

That was easy? See Puppet Reading List.
Tested with puppet 2.7.11-1ubuntu2.2 on Ubuntu 12.04 LTS precise 32-bit.

Posted in Uncategorized | Tagged , , , , , , , , , , | Comments Off on Hello Puppet revisited – on Ubuntu 12.04 LTS

Comments are closed.