walexey
2010-Oct-15 07:40 UTC
[Puppet Users] how can i determinate from one class if another class applied?
Hello everybody! How can i determinate from one class if another class applied to the this node? -- 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.
Bruce Richardson
2010-Oct-15 07:44 UTC
Re: [Puppet Users] how can i determinate from one class if another class applied?
On Fri, Oct 15, 2010 at 12:40:57AM -0700, walexey wrote:> Hello everybody! > How can i determinate from one class if another class applied to the > this node?Use the defined() function. -- Bruce What would Edward Woodward do? -- 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.
Felix Frank
2010-Oct-15 07:45 UTC
Re: [Puppet Users] how can i determinate from one class if another class applied?
On 10/15/2010 09:40 AM, walexey wrote:> Hello everybody! > How can i determinate from one class if another class applied to the > this node? >You can use the defined() function. if defined(Class[my_class]) { ... } YOU SHOULD NOT DO THAT, though. There are problems, because puppet may include classes in a different order in each run. See the details in http://docs.puppetlabs.com/references/stable/function.html#defined If the class you test for belongs to an earlier stage (in 2.6.0+), this problem may be sidestepped. I''m not sure if that''s how that works, though. HTH, Felix -- 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.
luke.bigum
2010-Oct-15 08:04 UTC
[Puppet Users] Re: how can i determinate from one class if another class applied?
What you''ll probably want is the tagged() function, not defined(). Someone correct me if I am wrong, but defined() is useful for checking if types or classes exist ("are known about") but does not check whether a class is DECLARED - there''s a difference. Note the documentation sentence "This is useful for checking whether a class is defined and only including it if it is". So if you have a master imports a manifest with a class called "foo" then: if defined(foo) == true (always) if tagged(foo) == true (only if your node has ''include foo'') What Felix says about the defined() function I beleive only applies to checking for specific resources, which depends on the specific parse order (and all you have to do is run ''puppetd --noop --test -- evaltrace'' to see the parse order changes ALL the time). On Oct 15, 8:40 am, walexey <wale...@gmail.com> wrote:> Hello everybody! > How can i determinate from one class if another class applied to the > this node?-- 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.
Bruce Richardson
2010-Oct-15 09:40 UTC
Re: [Puppet Users] Re: how can i determinate from one class if another class applied?
On Fri, Oct 15, 2010 at 01:04:29AM -0700, luke.bigum wrote:> Someone correct me if I am wrong, but defined() is useful for checking > if types or classes exist ("are known about") but does not check > whether a class is DECLARED - there''s a difference. Note the > documentation sentence "This is useful for checking whether a class is > defined and only including it if it is".You''re not wrong. That said, I''d actually advice the OP against trying this kind of thing. Generally, I find specific class dependencies are something to avoid. The only place I tolerate them is in "role" classes, which is where I usually set up any dependencies between modules that are required, and there I don''t need to use defined() or tagged() to check them, because I know precisely which classes have been included. Every time you add a dependency to a specific class, you cause problems for the person who finds a need to creat a new class that inherits from it. That person will often be you and kicking yourself is not rewarding. Looking at my manifests and modules, the *only* places I have a dependency on a named class is in my site::role classes and in the samba::packages class where the named classes are internal to the samba module and contain collections of packages (and their dependencies) relevant to specific versions of Samba. -- Bruce Explota!: miles de lemmings no pueden estar equivocados. -- 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.
walexey
2010-Oct-15 14:06 UTC
[Puppet Users] Re: how can i determinate from one class if another class applied?
I have following problem: defined class ldap-client, which install and configure ldap on _all_ nodes. there is file[/etc/nsswitch.conf]. it add ''ldap'' to nsswitch.conf defined class winbind, which install and configure winbind on _some_ nodes. and it need also to change nsswitch.conf, adding ''winbind'' there. i can''t imaging something better than add if tagged(winbind) { $winbind = ''winbind'' } else { $winbind = '''' } in ldap-client class and add passwd: files <%= winbind %> ldap to nsswithch.conf template. can you show me the right way? btw, my solution don''t work. tagged(winbind) in ldap-client return always false, but winbind class runs ok. On 15 окт, 13:40, Bruce Richardson <itsbr...@workshy.org> wrote:> On Fri, Oct 15, 2010 at 01:04:29AM -0700, luke.bigum wrote: > > Someone correct me if I am wrong, but defined() is useful for checking > > if types or classes exist ("are known about") but does not check > > whether a class is DECLARED - there''s a difference. Note the > > documentation sentence "This is useful for checking whether a class is > > defined and only including it if it is". > > You''re not wrong. That said, I''d actually advice the OP against trying > this kind of thing. Generally, I find specific class dependencies are > something to avoid. The only place I tolerate them is in "role" > classes, which is where I usually set up any dependencies between > modules that are required, and there I don''t need to use defined() or > tagged() to check them, because I know precisely which classes have been > included. > > Every time you add a dependency to a specific class, you cause problems > for the person who finds a need to creat a new class that inherits from > it. That person will often be you and kicking yourself is not > rewarding. Looking at my manifests and modules, the *only* places I > have a dependency on a named class is in my site::role classes and in > the samba::packages class where the named classes are internal to the > samba module and contain collections of packages (and their > dependencies) relevant to specific versions of Samba. > > -- > Bruce > > Explota!: miles de lemmings no pueden estar equivocados.-- 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.
Bruce Richardson
2010-Oct-15 15:40 UTC
Re: [Puppet Users] Re: how can i determinate from one class if another class applied?
On Fri, Oct 15, 2010 at 07:06:52AM -0700, walexey wrote:> i can''t imaging something better than add > > if tagged(winbind) { > $winbind = ''winbind'' > } else { > $winbind = '''' > } > in ldap-client class > > and add > passwd: files <%= winbind %> ldap > to nsswithch.conf template. > > can you show me the right way? >There is more than one way to do this. A simple way would be to use a variable to indicate whether you want winbind integration. Then anything that needs to know whether winbind is active can just check the variable - including the piece of code where you decide whether nor not to include the winbind class/module. The canonical Puppet way of dealing with it is to write a custom resource to manage nsswitch.conf. How good are your ruby skills? I have found a way to abuse virtual define-based resources so that you can effectively write your own custom resources in the Puppet DSL, rather than using Ruby, which I consider to be overkill for a case as simple as this. I will write it up when I have a moment, this weekend. Meanwhile, if you aren''t great at Ruby, I suggest the simple method I described first. node "host.on.which.I.want.winbind.active" { $winbind_integration = true include site::role::server } class site::role::server { if $winbind_integration { include samba::winbind } } ---- nsswitch.conf.erb ---- passwd: files <% if winbind_integration == true %>winbind<% end %> ldap ---- nsswitch.conf.erb ---- It''s not the most elegant solution (not the last bit, anyway) but it works and if you can''t trust yourself to set the right variables in the correct hosts, who can you trust? -- Bruce Bitterly it mathinketh me, that I spent mine wholle lyf in the lists against the ignorant. -- Roger Bacon, "Doctor Mirabilis" -- 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.
Felix Frank
2010-Oct-18 07:13 UTC
Re: [Puppet Users] Re: how can i determinate from one class if another class applied?
On 10/15/2010 05:40 PM, Bruce Richardson wrote:> On Fri, Oct 15, 2010 at 07:06:52AM -0700, walexey wrote: >> i can''t imaging something better than add >> >> if tagged(winbind) { >> $winbind = ''winbind'' >> } else { >> $winbind = '''' >> } >> in ldap-client class >> >> and add >> passwd: files <%= winbind %> ldap >> to nsswithch.conf template. >> >> can you show me the right way? >> > > There is more than one way to do this.So true... ;-) If there are only those two flavors of nsswitch.conf files in your network (or very few more), you might put it in a class of its own: class nsswitch_conf { file { "/etc/nsswitch.conf": content => "..." } } Then add the proper passwd line in a subclass: class nsswitch_conf_winbind inherits nsswitch_conf { File["/etc/nsswitch.conf"] { content => "...\npasswd: files windbind ldap\n..." } } This approach is limited, but you could as well use your template in the nsswitch_conf class and set different variables in the subclass. (Remember to still use the override as sketched above, simply setting variables will do no good in a subclass). That still saves you from the scoping and order fuss. Each of your nodes will include nsswitch_conf per default, an in your ldap client class, you will additionally include nsswitch_conf_winbind. Regards, Felix -- 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.