Do you mean "test if a resource is already defined"? If you define a resource (ie, file {}
, etc) Puppet will create what you're describing if doesn't already exist (assuming you pass ensure => present
, of course).
To check if a resource is already defined in the catalog or not:
mark-draytons-macbook:~ mark$ cat test.pp
file { "/tmp/foo": ensure => present }
if defined(File["/tmp/foo"]) {
alert("/tmp/foo is defined")
} else {
alert("/tmp/foo is not defined")
}
if defined(File["/tmp/bar"]) {
alert("/tmp/bar is defined")
} else {
alert("/tmp/bar is not defined")
}
mark-draytons-macbook:~ mark$ puppet test.pp
alert: Scope(Class[main]): /tmp/foo is defined
alert: Scope(Class[main]): /tmp/bar is not defined
notice: //File[/tmp/foo]/ensure: created
Note: defined()
is dependent on parse order.