I looked at the language tutorial but couldn''t see it anywhere. Is there a way to check if a class is included i.e. if class["myclass"] { myvar = "hello" } Thanks, Matt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
James Turnbull
2009-Aug-20 12:33 UTC
[Puppet Users] Re: Check to see if a class is included
Matt wrote:> I looked at the language tutorial but couldn''t see it anywhere. >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)
Every class you create is a tag. 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
I saw that but I think that did something else. 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 <james@lovedthanlost.net>:> Matt wrote: >> I looked at the language tutorial but couldn''t see it anywhere. >> > > 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) > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
if you have a complex variables setup, I really recommend to move away to external nodes(http://reductivelabs.com/trac/puppet/wiki/ExternalNodes) or extlookup( http://nephilim.ml.org/~rip/puppet/extlookup.rb) if you use external nodes, you could use an external source (e.g. a database, or web service like GNI) to define your variables on a node level. my 0.01 cents Ohad On Thu, Aug 20, 2009 at 9:34 PM, Matt <mattmoran76@gmail.com> wrote:> > I saw that but I think that did something else. > > 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 <james@lovedthanlost.net>: > > Matt wrote: > >> I looked at the language tutorial but couldn''t see it anywhere. > >> > > > > 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) > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
I want to keep away as much as possible from defining these variables at the node level as they are more linked to the included classes. 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. Being able to build an array of filenames based on ''if class is included'' would do the trick quickly. 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 :-) 2009/8/20 Ohad Levy <ohadlevy@gmail.com>:> if you have a complex variables setup, I really recommend to move away to > external nodes(http://reductivelabs.com/trac/puppet/wiki/ExternalNodes) or > extlookup( > http://nephilim.ml.org/~rip/puppet/extlookup.rb) > > if you use external nodes, you could use an external source (e.g. a > database, or web service like GNI) to define your variables on a node level. > > my 0.01 cents > Ohad > > On Thu, Aug 20, 2009 at 9:34 PM, Matt <mattmoran76@gmail.com> wrote: >> >> I saw that but I think that did something else. >> >> 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 <james@lovedthanlost.net>: >> > Matt wrote: >> >> I looked at the language tutorial but couldn''t see it anywhere. >> >> >> > >> > 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) >> > >> > >> >> > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, Aug 21, 2009 at 12:05 AM, Matt <mattmoran76@gmail.com> wrote:> > 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 think thats exactly what external nodes is design for...> > > 2009/8/20 Ohad Levy <ohadlevy@gmail.com>: > > if you have a complex variables setup, I really recommend to move away to > > external nodes(http://reductivelabs.com/trac/puppet/wiki/ExternalNodes) > or > > extlookup( > > http://nephilim.ml.org/~rip/puppet/extlookup.rb<http://nephilim.ml.org/%7Erip/puppet/extlookup.rb> > ) > > > > if you use external nodes, you could use an external source (e.g. a > > database, or web service like GNI) to define your variables on a node > level. > > > > my 0.01 cents > > Ohad > > > > On Thu, Aug 20, 2009 at 9:34 PM, Matt <mattmoran76@gmail.com> wrote: > >> > >> I saw that but I think that did something else. > >> > >> 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 <james@lovedthanlost.net>: > >> > Matt wrote: > >> >> I looked at the language tutorial but couldn''t see it anywhere. > >> >> > >> > > >> > 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) > >> > > >> > > >> > >> > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Hi> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Peter, What sets: if $use_nagios { include silc::nagios } Thanks, Matt 2009/8/20 Peter Meier <peter.meier@immerda.ch>:> > Hi > >> 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 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Hi> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Looks sensible to me. Thanks Peter i''ll give that way a go. 2009/8/21 Peter Meier <peter.meier@immerda.ch>:> > Hi > >> 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 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---