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

Making classes more flexible through parameters

Up until this point, classes and defines were presented as direct opposites with respect to flexibility; defined types are inherently adaptable through different parameter values, whereas classes model just one static piece of state. As the section title suggests, this is not entirely true. Classes too can have parameters. Their definition and declaration become rather similar to those of defined types in this case:

class apache::config($max_clients=100) { 
    file { 
        '/etc/apache2/conf.d/max_clients.conf': 
            content => "MaxClients $max_clients\n" 
    }       
}   
class { 
    'apache::config': 
        max_clients => 120; 
}

This enables some very elegant designs, but introduces some drawbacks as well.

Caveats of parameterized classes ...

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