Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if a class exists

Tags:

puppet

Is there a way to check in manifest files if a given class exists?

I want to do something like this:

class foo {
    if exists( Class["foo::${lsbdistcodename}"] ) {
        include foo::${lsbdistcodename}
    }
}

So I can easily add distrubution / version specific classes which are then automatically included.

like image 215
Michael Krupp Avatar asked Feb 26 '13 18:02

Michael Krupp


People also ask

Which function is used to check if class is exist or not?

The class_exists() function in PHP checks if the class has been defined. It returns TRUE if class is a defined class, else it returns FALSE.

How do you check the class is exist or not in jQuery?

jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".


1 Answers

You should use defined instead of exists statement. The following snippet works for me:

class foo {
    if defined( "foo::${lsbdistcodename}") {
            notify {'defined':}             
            include "foo::${lsbdistcodename}"
    }
}

class foo::precise {
    notify{'precise':}
}

[assuming you're running puppet version > 2.6.0]

like image 192
LiorH Avatar answered Sep 21 '22 13:09

LiorH