Skip to Content
Managing Infrastructure with Puppet
book

Managing Infrastructure with Puppet

by James Loope
June 2011
Beginner
56 pages
1h 13m
English
O'Reilly Media, Inc.
Content preview from Managing Infrastructure with Puppet

Chapter 2. Puppeteering

Before we can get into a full-scale example, we need to add more tools to our Puppet workbench. Puppet provides several layers of abstraction to give you a variety of options for structuring configurations.

Defines

In this example, I’ve defined a type called yellifmissing, which takes a parameter $path. Then I can instantiate an instance of yellifmissing called pathnumber1 and pass the path parameter /tmp/filenumber1. Then I can do it again. Each of these resource declarations will email me about the specified missing file. Using a defined type, I can compartmentalize and duplicate blocks of logic, similar to an instance class in most object-oriented languages:

define yellifmissing ($path) {
    exec { mailaboutit:
            command => "echo 'OhNoes!' | mail -s '$name is missing' admin@example.com",
            unless => "test -f $path",
            }
    }

yellifmissing { pathnumber1: path => '/tmp/filenumber1' }
yellifmissing { pathnumber2: path => '/tmp/filenumber2' }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Puppet Types and Providers

Puppet Types and Providers

Dan Bode, Nan Liu
Pro Puppet, Second Edition

Pro Puppet, Second Edition

Spencer Krum, William Van Hevelingen, Ben Kero, James Turnbull, Jeffery McCune
Mastering Puppet

Mastering Puppet

Thomas Uphill

Publisher Resources

ISBN: 9781449309671Errata Page