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

Avoiding antipatterns

Speaking of things to avoid, there is a language feature that I will only address in order to advise great caution. Puppet comes with a function called defined that allows you to query the compiler about resources that have been declared in the manifest:

if defined(File['/etc/motd']) {
    notify { 'This machine has a MotD': }
}

The problem with the concept is that it cannot ever be reliable. Even if the resource appears in the manifest, the compiler might encounter it later than the if condition. This is potentially very problematic, because some modules will try to make themselves portable through this construct:

if ! defined(Package['apache2']) {
    package {
        'apache2':
            ensure => 'installed'
    }
}

The module author supposes that this ...

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