robert.gstoehl
2010-Feb-17 08:56 UTC
[Puppet Users] Traversal of class inheritance - chain
Can one include muliple parts of a (class) - inheritance chain? And if yes, how does this chain get traversed? Are there any limitations / sideffects / documentation? The idea behind is: I''d like to provide a base set of disabled services. Each of this service can be enabled through inheriting from the base class and overriding the ensure / enable attributes. suppose the following: node foobar { include base include syslog include ueber_syslog } #disables syslog - just as an example ;) class base { service {"svc:/system/system-log:default": ensure => stopped, enable => false } } #enables syslog class syslog inherits base { Service["svc:/system/system-log:default"]{ ensure => running, enable => true } } #disables syslog and enables uebersyslog class ueber_syslog inherits syslog { Service["svc:/system/system-log:default"]{ ensure => stopped, enable => false } service {"svc:/system/uebersyslog:default": ensure => running, enable => true } } Thanks for your input. Cheers Robert -- 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.
jcbollinger
2010-Feb-17 14:50 UTC
[Puppet Users] Re: Traversal of class inheritance - chain
On Feb 17, 2:56 am, "robert.gstoehl" <robert.gsto...@gmail.com> wrote:> Can one include muliple parts of a (class) - inheritance chain? And if > yes, how does this chain get traversed? Are there any limitations / > sideffects / documentation?You can include classes from multiple parts of an inheritance tree, including classes from different branches of the tree, provided that there are no conflicting overrides. Two overrides conflict if they attempt to set different values for the same resource property, and they occur in two classes where neither is a descendant of the other. The two overrides in your "syslog" and "ueber_syslog" classes are perfect examples of conflicting overrides. I see nothing wrong with your classes individually, but including both "syslog" and "ueber_syslog" on the same node will fail. That makes sense, because doing so declares that the syslog service must be both running and stopped, which is impossible. There is no problem, however, with including class "base" along with either one of the other two. The solution, quite simply, is to avoid declaring conflicting resources or resource properties. In the example, that means each node may include at most one of the "syslog" and "ueber_syslog" classes. To achieve that you can hard-code per node group which class to use, use "if" or "case" statements to choose one class for each node based on its available facts, or use an external node classifier. Cheers, John -- 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.
robert.gstoehl
2010-Feb-17 16:16 UTC
[Puppet Users] Re: Traversal of class inheritance - chain
Hey John, Thanks for the clarification. Makes kind of sense ;) Cheers Robert On Feb 17, 3:50 pm, jcbollinger <John.Bollin...@stJude.org> wrote:> On Feb 17, 2:56 am, "robert.gstoehl" <robert.gsto...@gmail.com> wrote: > > > Can one include muliple parts of a (class) - inheritance chain? And if > > yes, how does this chain get traversed? Are there any limitations / > > sideffects / documentation? > > You can include classes from multiple parts of an inheritance tree, > including classes from different branches of the tree, provided that > there are no conflicting overrides. Two overrides conflict if they > attempt to set different values for the same resource property, and > they occur in two classes where neither is a descendant of the other. > > The two overrides in your "syslog" and "ueber_syslog" classes are > perfect examples of conflicting overrides. I see nothing wrong with > your classes individually, but including both "syslog" and > "ueber_syslog" on the same node will fail. That makes sense, because > doing so declares that the syslog service must be both running and > stopped, which is impossible. There is no problem, however, with > including class "base" along with either one of the other two. > > The solution, quite simply, is to avoid declaring conflicting > resources or resource properties. In the example, that means each > node may include at most one of the "syslog" and "ueber_syslog" > classes. To achieve that you can hard-code per node group which class > to use, use "if" or "case" statements to choose one class for each > node based on its available facts, or use an external node classifier. > > Cheers, > > John-- 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.