Kubes
2013-Mar-20 12:37 UTC
[Puppet Users] Correct means to tell if a class is instantiated/defined
All, I am using puppet 3.1.1 and I need to know if a class has been defined. I have tried defined() and tagged(), but neither seem to work. They either return true when the class was not include for that node or false when it is included. Here is the use case: My admin users are defined (virtual) in a class and I need to add them to groups for different nodes. As groups cant be have their members managed, but rather user have their membership managed. For example the mysql group for database servers and httpd for web servers. #in the service class there is a tag(''''mysql-serve'') if tagged(''mysql-server'') { $groups = [ ''wheel'', $mysql::params::group ] } else { $groups = [''wheel'' ] } #My understand is NOT to use Class[''mysql::service''] if defined(''mysql::service'') { $groups = [ ''wheel'', $mysql::params::group ] } else { $groups = [''wheel'' ] } Thanks! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Felix Frank
2013-Mar-20 12:43 UTC
Re: [Puppet Users] Correct means to tell if a class is instantiated/defined
Hi, On 03/20/2013 01:37 PM, Kubes wrote:> I am using puppet 3.1.1 and I need to know if a class has been defined. > I have tried defined() and tagged(), but neither seem to work. They > either return true when the class was not include for that node or falseplease don''t. You''re making yourself parse order dependent and that *will* bite you at some point down the road. Do not even try. You may get away with declaring a subclass instead, and have class mysql::service include that subclass in order to achieve the necessary modification. Otherwise, your best choice is probably external data, as in hiera. That being said:> when it is included. #My understand is NOT to use Class[''mysql::service'']How have you come to understand this? I would have thought that Class[] is fine. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Kubes
2013-Mar-20 12:56 UTC
Re: [Puppet Users] Correct means to tell if a class is instantiated/defined
Thanks for the response. On Wednesday, March 20, 2013 8:43:00 AM UTC-4, Felix.Frank wrote:> > Hi, > > On 03/20/2013 01:37 PM, Kubes wrote: > > I am using puppet 3.1.1 and I need to know if a class has been defined. > > I have tried defined() and tagged(), but neither seem to work. They > > either return true when the class was not include for that node or false > > please don''t. You''re making yourself parse order dependent and that > *will* bite you at some point down the road. Do not even try. > >You may get away with declaring a subclass instead, and have class> mysql::service include that subclass in order to achieve the necessary > modification. > > I was checking for a subclass "mysql::service"> Otherwise, your best choice is probably external data, as in hiera. >Thanks, but I dont understand how heira solve the issues, can you please elaborator a bit for me? I an using heira for storing my user info, but I dont know how to use it to handle if a node is a db server, etc?> > That being said: > > > when it is included. #My understand is NOT to use > Class[''mysql::service''] > > How have you come to understand this? I would have thought that Class[] > is fine. >Via post on this group and the documentation. Using Resource[] is only needed for resource refferences, as I understand it. http://docs.puppetlabs.com/references/latest/function.html#defined -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Felix Frank
2013-Mar-20 13:04 UTC
Re: [Puppet Users] Correct means to tell if a class is instantiated/defined
Hi again, On 03/20/2013 01:56 PM, Kubes wrote:> You may get away with declaring a subclass instead, and have class > mysql::service include that subclass in order to achieve the necessary > modification. > > I was checking for a subclass "mysql::service"Not really. The class is named mysql::service, but I sincerely hope it is not inheriting anything. Point in fact - if you are not yet very keen on inheritance and how it works, I advise to steer clear for the moment.> Otherwise, your best choice is probably external data, as in hiera. > > Thanks, but I dont understand how heira solve the issues, can you please > elaborator a bit for me? I an using heira for storing my user info, but > I dont know how to use it to handle if a node is a db server, etc?You have it working already? Excellent! The idea is simple: Introduce a hiera value that, for each node, tells it whether it is a mysql server or not. Each last of your nodes can then e.g. if hiera("mysql-server") == "true" { include mysql } It is now trivial to use the same hiera value in other places.> How have you come to understand this? I would have thought that Class[] > is fine. > > > Via post on this group and the documentation. Using Resource[] is only > needed for resource refferences, as I understand it. > http://docs.puppetlabs.com/references/latest/function.html#definedAh, misunderstanding. defined() will tell you whether the class *exists*, not if this node has included the class. (At least that''s what I make of the documentation). HTH, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.