Puppet Resource Examples

Puppet Logo
This post starts Puppet series on Ubuntu 12.04 where we will look into Puppet in detail.

The first post will be about resources in Puppet and how they work. I will give you examples of every core resource type there is by default on Puppet.

This post will include all the core resource types found on Puppet. Notify, file, package, service, exec, cron, user and group.

Usage

You can use these by writing a file with the resource text and using puppet apply FILENAME.

Notify

Notify sends a message to the clients and will be saved to Puppet logs. Example sends “Notification to the clients”-text to the logs.

File

With File resource you can control everything about files. This example writes some data into /tmp/helloPuppet -file.

Package

Package resource gives you management over installable packages. On the example I’m installing package via apt-get. Remember you have to use sudo to do installation of packages.

Service

Service resource manages services running on the client for example Apache2. The following example checks that Apache2 is running, if it’s not it will be started.

Exec

Exec resource as it’s name says executes something. For example the following will apt-get update.

Cron

Cron creates and controls cron jobs in the system. For example we can run logrotate every day at 05:00.

User

With User resource we can control users and mostly system users. On the example we set users full name as comment to user lennu.

Group

Group resource is made for managing groups and mostly creating them. Example ensures the lennu.net -group exists. If it doesn’t, it will be created.

Documentation

That’s for core resource types, you can find all the details and rest of the attributes used by Puppet from their documentation.

I hope you found this page useful! If you have any questions about the examples, please post a comment and we’ll see if I can help you out.