Boudewijn Ector
2013-Jul-01 21:09 UTC
[Puppet Users] Inheriting variables from supernode into lower nodes
Hi Guys, I''d like to have some default values which are used in templates to be inherited from the basenode hosts. I tried, but I can''t get it to work. This is my setup: Currently, I''m trying to do something like this: node basenode { include ntp include postfix include denyhosts include ssh include nrpe <et cetera> } in my node definition file. Then I do: import "internal-nodes" in the same file. Then in internal-nodes.pp : node ''internal-node'' inherits basenode { $internalIP = true } node ''vpn.XXX.nl'' inherits internal-node { } The internalIP variable is being used in templates for the vpn.xxx.nl host, but it doesn''t seem to get set properly. The code in the ERB template: <% if $internalIP == true %> foo <% else %> bar <% end %> This will just not work. How can I get this to work properly, I''d love to set the internalIP variable *just* in the ''internal-node'' class, and NOT in every internal client. Cheers, Boudewijn -- 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. For more options, visit https://groups.google.com/groups/opt_out.
Dan White
2013-Jul-02 00:50 UTC
Re: [Puppet Users] Inheriting variables from supernode into lower nodes
Node inheritance does not work like class inheritance. http://docs.puppetlabs.com/puppet/3/reference/lang_node_definitions.html#inheritance "Nodes can inherit from other nodes using the inherits keyword. Inheritance works identically to class inheritance. This feature is not recommended; see the aside below.” https://ask.puppetlabs.com/question/395/why-is-inheritance-frowned-upon/ https://groups.google.com/forum/#!topic/puppet-users/7OQPA9iKimM (Best Practices on node declaration) http://docs.puppetlabs.com/hiera/1/puppet.html#assigning-classes-to-nodes-with-hiera-hierainclude "You can use Hiera to assign classes to nodes with the special hiera_include function. This lets you assign classes in great detail without repeating yourself — it’s essentially what people have traditionally tried and failed to use node inheritance for.” And some food for thought: http://www.craigdunn.org/2012/05/239/ (Designing Puppet – Roles and Profiles) On Jul 1, 2013, at 5:09 PM, Boudewijn Ector wrote:> Hi Guys, > > I''d like to have some default values which are used in templates to be inherited from the basenode hosts. > I tried, but I can''t get it to work. This is my setup: > > > Currently, I''m trying to do something like this: > > node basenode { > include ntp > include postfix > include denyhosts > include ssh > include nrpe > <et cetera> > > } > in my node definition file. > Then I do: > > import "internal-nodes" > > in the same file. > > Then in internal-nodes.pp : > > node ''internal-node'' inherits basenode { > $internalIP = true > } > > node ''vpn.XXX.nl'' inherits internal-node { > } > > The internalIP variable is being used in templates for the vpn.xxx.nl host, but it doesn''t seem to get set properly. > The code in the ERB template: > > > <% if $internalIP == true %> > foo > <% else %> > bar > <% end %> > > > This will just not work. How can I get this to work properly, I''d love to set the internalIP variable *just* in the ''internal-node'' class, and NOT in every internal client. > > > Cheers, > > Boudewijn > > -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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. For more options, visit https://groups.google.com/groups/opt_out.