Bostjan Skufca
2012-Aug-26 19:29 UTC
[Puppet Users] Dynamic scoping deprecated - for defines also?
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. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/TYJCFw5F-joJ. 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.
Bruce
2013-Mar-07 20:08 UTC
[Puppet Users] Re: Dynamic scoping deprecated - for defines also?
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? -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
R.I.Pienaar
2013-Mar-07 20:10 UTC
Re: [Puppet Users] Re: Dynamic scoping deprecated - for defines also?
----- Original Message -----> From: "Bruce" <blysik@yahoo.com> > To: puppet-users@googlegroups.com > Sent: Thursday, March 7, 2013 8:08:54 PM > Subject: [Puppet Users] Re: Dynamic scoping deprecated - for defines also? > > 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?That doesn''t sound like a description of dynamic scoping. Best to show examples -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Bruce
2013-Mar-07 20:16 UTC
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'') %> 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! -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
R.I.Pienaar
2013-Mar-07 20:19 UTC
Re: [Puppet Users] Re: Dynamic scoping deprecated - for defines also?
----- Original Message -----> From: "Bruce" <blysik@yahoo.com> > To: puppet-users@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 -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Bruce
2013-Mar-07 22:49 UTC
Re: [Puppet Users] Re: Dynamic scoping deprecated - for defines also?
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. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
llowder
2013-Mar-08 13:51 UTC
Re: [Puppet Users] Re: Dynamic scoping deprecated - for defines also?
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 -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Felix Frank
2013-Mar-08 15:53 UTC
Re: [Puppet Users] Dynamic scoping deprecated - for defines also?
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 } -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.