Dynamic scoping deprecated - for defines also?

99 views
Skip to first unread message

Bostjan Skufca

unread,
Aug 26, 2012, 3:29:06 PM8/26/12
to puppet...@googlegroups.com
Hello,

in my logs I noticed deprecation warnings like this one:
Dynamic lookup of $VARIABLE at FILE:LINE is deprecated. For more information, see http://docs.puppetlabs.com/guides/scope_and_puppet.html. To see the change in behavior, use the --debug flag.

Ok, I go to the URL, I can see the reasoning behind this. BUT!

In the code I do not use classes that trigger this warning, but defines.

Example that I would expect would trigger the warning above:
---------------------------------------------------------------------------------------
### File: module1/manifests/dir/file.pp
class module1::dir::file {
    resource1 {...} # Uses $param3
    resource2 {...}
    resource3 {...}
}


### File: module2/manifests/something.pp
class   module2::something {
   $param3 = 'asdf'
   include 'module1::dir::file'
}
----------------------------------------------------------------------------------------



Example below that I use (not with class inclusion, but with "define"s),
and it was not expected to trigger warning, because:
---------------------------------------------------------------------------------------
### File: module1/manifests/dir/file.pp
define   module1::dir::file {
    resource1 {...}    # Uses $param3
    resource2 {...}
    resource3 {...}
}


### File: module2/manifests/something.pp
class   module2::something {
   $param3 = 'asdf'
   module1::dir::file { "someName": param1=>1 }
}
----------------------------------------------------------------------------------------

Defines are not exempt to that deprecation? How come?

b.

Bruce

unread,
Mar 7, 2013, 3:08:54 PM3/7/13
to puppet...@googlegroups.com
No response to this?  I'm trying to clean up code to eventually move to 3.x, and I'm running into this as well.  Have defines with variables and then templates which reference those variables.  How do I explicitly scope it?

R.I.Pienaar

unread,
Mar 7, 2013, 3:10:28 PM3/7/13
to puppet...@googlegroups.com
That doesn't sound like a description of dynamic scoping. Best to show examples

Bruce

unread,
Mar 7, 2013, 3:16:26 PM3/7/13
to puppet...@googlegroups.com


That doesn't sound like a description of dynamic scoping.  Best to show examples

Sure thing.

class foo {
  define add_foo ( $foo_name ) {
    file { '/etc/some/file':   content => template("foo/file.erb")
  }
}

Then in file.erb:

<%= scope.lookupvar('foo::add_foo::foo_name') %>

So that scope lookup doesn't work, and I couldn't find out a way to do it correctly.

Any help would be appreciated.  Thanks!

R.I.Pienaar

unread,
Mar 7, 2013, 3:19:59 PM3/7/13
to puppet...@googlegroups.com


----- Original Message -----
> From: "Bruce" <bly...@yahoo.com>
> To: puppet...@googlegroups.com
> Sent: Thursday, March 7, 2013 8:16:26 PM
> Subject: Re: [Puppet Users] Re: Dynamic scoping deprecated - for defines also?
>
>
>
> That doesn't sound like a description of dynamic scoping. Best to show
> > examples
> >
>
> Sure thing.
>
> class foo {
> define add_foo ( $foo_name ) {
> file { '/etc/some/file': content => template("foo/file.erb")
> }
> }
>
> Then in file.erb:
>
> <%= scope.lookupvar('foo::add_foo::foo_name') %>

just do <%= @foo_name %> the vars in the define is local scope, just use them

Bruce

unread,
Mar 7, 2013, 5:49:38 PM3/7/13
to puppet...@googlegroups.com


just do <%= @foo_name %> the vars in the define is local scope, just use them

This worked great.  I'm a little shaky on when I can use @variables.  Is there documentation you could point me at?  Thanks again. 

llowder

unread,
Mar 8, 2013, 8:51:07 AM3/8/13
to puppet...@googlegroups.com


On Thursday, March 7, 2013 4:49:38 PM UTC-6, Bruce wrote:


just do <%= @foo_name %> the vars in the define is local scope, just use them

This worked great.  I'm a little shaky on when I can use @variables.  Is there documentation you could point me at?  Thanks again. 

Any variable that is a local variable to the manifest calling the template, or any fact.  Only docs I know of are at http://docs.puppetlabs.com/guides/templating.html#referencing-variables

Felix Frank

unread,
Mar 8, 2013, 10:53:26 AM3/8/13
to puppet...@googlegroups.com
On 08/26/2012 09:29 PM, Bostjan Skufca wrote:
> ### File: module2/manifests/something.pp
> class module2::something {
> $param3 = 'asdf'
> module1::dir::file { "someName": param1=>1 }
> }
> ----------------------------------------------------------------------------------------
>
> Defines are not exempt to that deprecation? How come?

To answer the original inquiry:

You are not supposed to do that. Instead, add a "param3" parameter to
your defined type and pass the value explicitly, so that puppet can
scope any references statically.

module1::dir::file { "someName": param1=>1, param3 => $param3 }
Reply all
Reply to author
Forward
0 new messages