This doesn''t appear to be documented in the book or the wiki (except by the absence of documentation). I have a series of node foo inherits bar {} in my site.pp. This sets up a chain like base -> workstation -> thinkpad -> thinkpadt43. I have a function defined as puppet_file(). It takes the usual file() arguments, but sets up the source parameter with the full puppet host and file share etc, then concatenates the argument $source appropriately. I''ve also got some other arguments on puppet_file() that I want to use to set up paths inside of a source array (which I see Luke calls a bug, I call a useful feature). If I pass them explicitly, then everything works properly. If I go: node foo inherits bar { $variable = ''workstations'' puppet_file { "mail_aliases": ...... } } puppet_file doesn''t get the value of $variable inside of it. Is this scoping restriction deliberate? If so, lots more typing for me! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Duncan Hill
2008-Jun-10 12:40 UTC
[Puppet Users] Re: Variable scopes and defined functions
On Jun 10, 10:27 am, "Duncan Hill" <bajand...@googlemail.com> wrote:> This doesn''t appear to be documented in the book or the wiki (except > by the absence of documentation).> node foo inherits bar { > $variable = ''workstations'' > puppet_file { > "mail_aliases": > ...... > } > > } > > puppet_file doesn''t get the value of $variable inside of it. Is this > scoping restriction deliberate? If so, lots more typing for me!And now that I think about it, I have a reason why this is the way it is. Inheriting variable definitions from the scope would lead to conflicts between variable names and function arguments. Defining a variable called ''source'' could lead to some interesting file() calls where you''re just ensuring a directory exists. At least I can define $variable way up in the inheritance chain, and have that cascade down, overriding when needed. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---