Hi All, How would I go about achieving the following? node basenode { include motd } node www inherits basenode { $purpose = "web server" } In the "motd" module, I have a template that formats a standard /etc/motd file and I want to make use of the $purpose variable. When I access scope.lookupvar(''::purpose''), I get undefined. Thanks, Gonzalo -- 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.
On Nov 17, 3:16 pm, Gonzalo Servat <gser...@gmail.com> wrote:> Hi All, > > How would I go about achieving the following? > > node basenode { > include motd > > } > > node www inherits basenode { > $purpose = "web server" > > } > > In the "motd" module, I have a template that formats a standard /etc/motd > file and I want to make use of the $purpose variable. When I access > scope.lookupvar(''::purpose''), I get undefined.I''m sure you do. Class[''motd''] is evaluated in the scope of node ''basenode'', which does not define a variable of that name. Moreover, node variables are not in top scope and do not have qualified names, so your particular use of scope.lookupvar() would not work anyway. You have a great use case here for external data: instead of using a node variable to communicate the machine''s purpose, you could instead have class motd look it up via extlookup() or hiera. Alternatively, if you were using an ENC then it would be easy to set $purpose as a global variable, in which case your current template would be right. There are also approaches involving class inheritance in addition to node inheritance. If you''re considering node basenode abstract, meaning that every client must match a subnode rather than basenode itself, then you could parameterize class motd and have each subnode pass the purpose variable that way (basenode would no longer declare motd). I''m not fond of class parameterization, but it could work. 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.
Gonzalo Servat
2011-Nov-19 00:20 UTC
Re: [Puppet Users] Re: Variables inside node definition
On Sat, Nov 19, 2011 at 12:58 AM, jcbollinger <John.Bollinger@stjude.org>wrote:> [..snip..] >>You have a great use case here for external data: instead of using a> node variable to communicate the machine''s purpose, you could instead > have class motd look it up via extlookup() or hiera. >Thanks for replying John. I hadn''t looked into extlookup() until you mentioned this. It''s just what I need! I also have a custom facter variable that defines which data centre the server is in, which fits in nicely with extlookup() to look into a dc-specific CSV file. I''m not using ENC as I do call a few defines from node definitions, and I don''t think there is a way of calling defines from a YAML node definition? Thanks again for the pointer! - Gonzalo -- 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.
On Nov 18, 6:20 pm, Gonzalo Servat <gser...@gmail.com> wrote:> On Sat, Nov 19, 2011 at 12:58 AM, jcbollinger <John.Bollin...@stjude.org>wrote: > > > [..snip..] > > You have a great use case here for external data: instead of using a > > > node variable to communicate the machine''s purpose, you could instead > > have class motd look it up via extlookup() or hiera. > > Thanks for replying John. I hadn''t looked into extlookup() until you > mentioned this. It''s just what I need! I also have a custom facter variable > that defines which data centre the server is in, which fits in nicely with > extlookup() to look into a dc-specific CSV file.Great, I''m glad to hear it.> I''m not using ENC as I do call a few defines from node definitions, and I > don''t think there is a way of calling defines from a YAML node definition?You are correct. External node classifiers cannot declare individual resources, including defined type instances. You would have to wrap yours in classes to use an ENC. I''m sure it would be possible, but it might be more work than you want to undertake right now. 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.