O'Reilly logo

Puppet Essentials by Felix Frank

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nesting definitions in classes

A somewhat obscure feature of the language is the nesting of containers inside class bodies. Both classes and defined types can be part of a class body. This allows the nested container to access variables that are local to the enclosing class:

class example_app { 
    $config_dir = '/etc/example_app' 
    define symlink { 
        "$config_dir/conf.d.enabled/$name": 
            ensure => 'link', 
            target => "../conf.d.available/$name", 
    } 
    …
}

Even without a (contrived) shared variable, it is actually not a bad idea to define such macro-style types right in the class that makes exclusive use of them.

Note

It is important to realize that this does not protect the defined type from invocation anywhere else in your manifest. Puppet has no concept of private ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required