Jos Houtman
2012-Feb-20 16:24 UTC
[Puppet Users] Parameterized classes override of parameter
Hi group, I expect parameterized classes to behave simular to types in relation to overrides, but obviously this is not the case. Could someone what is should then expect from overriding an parameterized class. what I have is: class dns(dns_servers) { file{''/etc/resolv.conf'': content => template("dns/resolv.conf.erb") } } class role::init { class{''dns'': dns_servers => [''10.100.100.1''] } } class role::loadbalancer inherits role { Class[''dns''] { dns_servers => [''127.0.0.1''] } } node loadbalancer1 { include role::loadbalancer } I expected resolv.conf to have the 127.0.0.1 address, but it has the 10.100.100.1 address. Could someone explain to me the rules around parameterized class inheritence. And if using inheritence to override general use cases for very common modules is not the way, should all this logic then be put into our extlookup or something like hiera? Jos -- 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.
Nan Liu
2012-Feb-20 21:05 UTC
Re: [Puppet Users] Parameterized classes override of parameter
On Mon, Feb 20, 2012 at 8:24 AM, Jos Houtman <jos@hyves.nl> wrote:> Hi group, > > I expect parameterized classes to behave simular to types in relation > to overrides, but obviously this is not the case. > Could someone what is should then expect from overriding an parameterized class. > > what I have is: > > class dns(dns_servers) { > file{''/etc/resolv.conf'': > content => template("dns/resolv.conf.erb") > } > } > > class role::init { > class{''dns'': > dns_servers => [''10.100.100.1''] > } > } > > class role::loadbalancer inherits role { > Class[''dns''] { > dns_servers => [''127.0.0.1''] > } > } > > node loadbalancer1 { > include role::loadbalancer > } > > I expected resolv.conf to have the 127.0.0.1 address, but it has the > 10.100.100.1 address. > > Could someone explain to me the rules around parameterized class inheritence. > And if using inheritence to override general use cases for very common > modules is not the way, should all this logic then be put into our > extlookup or something like hiera?Parametrized classes do not behave like resources, so you can''t override them in an inherited class. In your case, either do not inherit and declare the class separately, or declare include ntp, and change class definition to dns(dns_servers=hiera(''dns_server'')) {...} Thanks, Nan -- 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.
Andrew Forgue
2012-Feb-21 05:02 UTC
Re: [Puppet Users] Parameterized classes override of parameter
This is actually filed in Bug #5517 (Accepted) and a few others and has 10 votes. http://projects.puppetlabs.com/issues/5517 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/T-tcPreqc10J. 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
2012-Feb-21 13:53 UTC
[Puppet Users] Re: Parameterized classes override of parameter
On Feb 20, 10:24 am, Jos Houtman <j...@hyves.nl> wrote:> Hi group, > > I expect parameterized classes to behave simular to types in relation > to overrides, but obviously this is not the case. > Could someone what is should then expect from overriding an parameterized class. > > what I have is: > > class dns(dns_servers) { > file{''/etc/resolv.conf'': > content => template("dns/resolv.conf.erb") > } > > } > > class role::init { > class{''dns'': > dns_servers => [''10.100.100.1''] > } > > } > > class role::loadbalancer inherits role { > Class[''dns''] { > dns_servers => [''127.0.0.1''] > } > > } > > node loadbalancer1 { > include role::loadbalancer > > } > > I expected resolv.conf to have the 127.0.0.1 address, but it has the > 10.100.100.1 address. > > Could someone explain to me the rules around parameterized class inheritence.Parameterized class inheritance is just like non-parameterized class inheritance. In fact, it is *exactly* like non-parameterized class inheritance, including that it provides no mechanism for the parameters of the superclass to be set when the subclass is declared.> And if using inheritence to override general use cases for very common > modules is not the way, should all this logic then be put into our > extlookup or something like hiera?My recommendation is to use hiera for all the needs you may now be addressing via class parameters. You may find that that also reduces your interest in class inheritence, but if you still want to use some inheritence then you won''t need to deal with parameterized base classes. 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.