On Sat, Oct 24, 2009 at 3:29 AM, Dick Davies
<rasput...@hellooperator.net> wrote:
>
> If I have something like this:
>
> ----------------------------------------
>
> define bar($thing="/tmp/$name") {
>  file { $thing: ensure => present }
> }
>
>
> class foo {  somedef{ "bar": } }
>
> ----------------------------------------
>
> puppet will try to create a file called '/tmp/foo' , not /tmp/bar.
> It seems like if I try to access $name inside the 'default arguments'
> bit of a definition,
> it's set to the enclosing class.
>
> I want to get at the name of the definition ('bar' in the above example).
>
> Once i'm inside the body of the definition, $name seems to be set correctly
> (inside templates called from the definition, etc.).
>
> [I'm writing an apache module, and want to infer a default docroot of
> '/docroot/www-vhostname',
> but allow an option to override it.
>
> how can I do that ? (and is this a bug?)

This isn't a bug. It is a natural consequence of scoping.

define bar() {
  $thing = "/tmp/$name"
  file { $thing: ensure => present }
}

should do what you want.

--Paul

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to