June 2011
Beginner
56 pages
1h 13m
English
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.
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' }