Is it possible to override in a sub-class a resource included by the parent class? The code I tried was: class yum_rtk { yumrepo { "rtk-dev": enabled => 0, } } class base_server { include yum_rtk } class dev_server inherits base_server { Yumrepo["rtk-dev"] { enabled => 1 } } But it gave an error, "Only subclasses can overri de parameters". Do I need to create a subclass of yum_rtk and include it in dev_server? - Ian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Schmitt
2008-Jun-04 09:14 UTC
[Puppet Users] Re: Override resource in included class
Ian Burrell schrieb:> Is it possible to override in a sub-class a resource included by the > parent class? The code I tried was: > > class yum_rtk { > yumrepo { "rtk-dev": > enabled => 0, > } > } > > class base_server { > include yum_rtk > } > > class dev_server inherits base_server { > Yumrepo["rtk-dev"] { enabled => 1 } > } > > But it gave an error, "Only subclasses can overri > de parameters". Do I need to create a subclass of yum_rtk and include > it in dev_server?class yum_rtk { yumrepo { "rtk-dev": enabled => 0, } } class base_server { include yum_rtk // other resources } class dev_server_yum inherits yum_rtk { Yumrepo["rtk-dev"] { enabled => 1 } } class dev_server inherits base_server { include dev_server_yum // override other resources here } Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
To expand on David''s practical example with some theory, it''s important to remember that there is a semantic difference between ''inheriting'' a class and ''including'' a class. When you ''include'' a class, you are essentially saying ''make sure this class gets evaluated.'' You are not creating any parent/child relationship. It''s more like saying ''I want to be sure these mostly-unrelated things happen alongside the current class.'' Thus, there is no ability to override resources. There''s a good reason for this; but I unfortunately can''t seem to figure out how to explain it w/o a whiteboard :-) I used to use ''include'' like inheritance, to simulate multiple-inheritance, until I understood the semantic difference. Now I''m just trying to figure out how to patch Puppet for multiple inheritance instead :-P --Paul On Wed, Jun 4, 2008 at 2:14 AM, David Schmitt <david@schmitt.edv-bus.at> wrote:> > Ian Burrell schrieb: >> Is it possible to override in a sub-class a resource included by the >> parent class? The code I tried was: >> >> class yum_rtk { >> yumrepo { "rtk-dev": >> enabled => 0, >> } >> } >> >> class base_server { >> include yum_rtk >> } >> >> class dev_server inherits base_server { >> Yumrepo["rtk-dev"] { enabled => 1 } >> } >> >> But it gave an error, "Only subclasses can overri >> de parameters". Do I need to create a subclass of yum_rtk and include >> it in dev_server? > > class yum_rtk { > yumrepo { "rtk-dev": > enabled => 0, > } > } > > class base_server { > include yum_rtk > // other resources > } > > class dev_server_yum inherits yum_rtk { > Yumrepo["rtk-dev"] { enabled => 1 } > } > > class dev_server inherits base_server { > include dev_server_yum > // override other resources here > } > > > Regards, DavidS > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 used to use ''include'' like inheritance, to simulate > multiple-inheritance, until I understood the semantic difference. Now > I''m just trying to figure out how to patch Puppet for multiple > inheritance instead :-P > > --Paul >Godd luck with that, I hope you do it soon :). Seriously though that will be a reaally nice feature. Evan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---