Is there a way to check if a class is included i.e.
if class["myclass"] {
myvar = "hello"
}
Thanks,
Matt
You might be looking for the defined function.
http://reductivelabs.com/trac/puppet/wiki/FunctionReference#defined
Regards
James Turnbull
--
Author of:
* Pro Linux Systems Administration (http://tinyurl.com/linuxadmin)
* Pulling Strings with Puppet (http://tinyurl.com/pupbook)
* Pro Nagios 2.0 (http://tinyurl.com/pronagios)
* Hardening Linux (http://tinyurl.com/hardeninglinux)
So:
if tagged('myclass') {
$myvar = "hello"
}
One caveat, is the class order can matter if the tag exists yet or not.
http://projects.reductivelabs.com/issues/2105
-L
--
Larry Ludwig
Reductive Labs
node "mynode" {
include myclass, foo
}
node "mynode2" {
include foo
}
class "foo" {
if defined(Class['myclass']) {myvar = "hello"})
}
Will both mynode2 and mynode get the variable myvar? In my case I
only want mynode too. If both do, then I guess I need to use tagged
as Larry said, but make sure that myclass is first in the include?
Thanks,
Matt
2009/8/20 James Turnbull <ja...@lovedthanlost.net>:
I guess another way would be for me to start building custom facters
of what a node is and then deploy the right files depending on the
facter result.
Anyone done similar? I always feel with puppet i'm missing something
obvious :-)
> I'm trying to set-up a monitoring module that looks at what
> classes(modules) have been included for that node and then deploys the
> required monitoring scripts.
For something like that I use exported resources, so within the class
itself I export a nagios-check, which then will be collected by the
nagios server and my service is monitored.
for example for something simple like a tcp port monitoring for silc:
http://git.puppet.immerda.ch/?p=module-silc.git;a=blob;f=manifests/init.pp;h=deecb092cbeaad7765a83c25c15bd939ab1a5f33;hb=d79d8c9d76599fb3dfdce2cf8d77dcd4c517bf97#l9
which includes the silc::nagios class, which declares a nagios::service
for silc:
http://git.puppet.immerda.ch/?p=module-silc.git;a=blob;f=manifests/nagios.pp;h=99ca7f970500882e45fe471670478a2444662823;hb=d79d8c9d76599fb3dfdce2cf8d77dcd4c517bf97
which is behind (in the nagios module) an exported nagios resource to
the nagios server.
a bit an alternative approach, but might fit your needs, doesn't it?
cheers pete
> What sets:
>
> if $use_nagios {
> include silc::nagios
> }
>
well I build my modules, so you can use them also without nagios
(default) so if you'd like to use nagios you set globally in your
site.pp the variable $use_nagios = true
It's just a variable which enable certain more features on the modules.
cheers pete