Using define resources

"Girl number twenty unable to define a horse!" said Mr. Gradgrind.—Charles Dickens, 'Hard Times'

Unless you know how to define what you want, you won't get it. In the preceding example, we saw how to reduce redundant code by grouping identical resources into arrays. However, this technique is limited to resources where all the parameters are the same. When you have a set of resources that have some parameters in common and some different, you need to use a define resource to group them together.

How to do it…

  1. Add the following to your manifest:
    define tmpfile() {
        file { "/tmp/$name":
            content => "Hello, world",
        }
    }
    
    tmpfile { ["a", "b", "c"]: }
  2. Run Puppet:
    notice: /Stage[main]//Node[cookbook]/Tmpfile[a]/File[/tmp/a]/ensure: defined ...

Get Puppet 2.7 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.