Issue #14402 has been updated by Andrew Parker.
Status changed from Investigating to Rejected
The error message that you are getting is completely correct (if maybe not the
most explicit about what is wrong). The problem is that `$a:b` is not a
reference to a variable named `$b` inside the `a` scope, it is simply a
reference to the variable `$a` followed by the gobbledygook `:b`. When this is
done in a string without the curly braces the interpolation simply sees a
reference to `$a`. When the curly braces get involved then it knows that you
mean the entire `a:b` as the variable name and starts trying to understand it
as such. Since `a:b` is not a valid variable name it throws an error.
I checked this on the 2.7 code as well as on the 2.6 code, both behave the same
way with respect to this.
You also mention that there are no deprecation warnings being issued for
lookups of dynamically scoped variables in erb templates, which could be a bug.
The `scope.lookupvar` function in templates should continue to work after 2.7,
but it will be affected by the removal of dynamic scoping in the same way that
variables inside the puppet language will be affected. Can you come up with
steps to reproduce that and file another ticket about that issue?
Examples of namespaced variable interpolation:
Using a single colon without curlies:
<pre>
class sayings {
$where = "hello"
}
include sayings
notify { "I say $sayings:where": }
</pre>
Produces:
<pre>
notice: I say :where
notice: /Stage[main]//Notify[I say :where]/message: defined 'message' as 'I say
:where'
notice: Finished catalog run in 0.02 seconds
</pre>
Using a single colon with curlies:
<pre>
class sayings {
$where = "hello"
}
include sayings
notify { "I say ${sayings:where}": }
</pre>
Produces:
<pre>
Could not parse for environment production: Syntax error at ':'; expected '}'
at /Users/andy/tmp/interpolation.pp:7 on node aparker.puppetlabs.lan
</pre>
Using a double colon with curlies:
<pre>
class sayings {
$where = "hello"
}
include sayings
notify { "I say ${sayings::where}": }
</pre>
Produces:
<pre>
notice: I say hello
notice: /Stage[main]//Notify[I say hello]/message: defined 'message' as 'I say
hello'
notice: Finished catalog run in 0.02 seconds
</pre>
----------------------------------------
Bug #14402: variable interpolation and scope
https://projects.puppetlabs.com/issues/14402#change-63093
Author: Gary Wilson (@earthgecko)
Status: Rejected
Priority: Normal
Assignee: Andrew Parker
Category:
Target version:
Affected Puppet version: 2.7.14
Keywords:
Branch:
I am somewhat lost in the changes in variable interpolation, the deprecation of
dynamic lookup and the styling guide documentation vs Scope and Puppet
documentation (http://docs.puppetlabs.com/guides/scope_and_puppet.html) and Bug
#10146: Puppet interpolates variables differently in 2.7.x
(https://projects.puppetlabs.com/issues/10146)
So with 2.7.x variables should be declared as `"/root/.ssh/${var}"` according
to #10146 (to be safe).
The following variable worked with dynamic lookup.
<pre>
file { "/root/.ssh/${ec2_cert}":
source => "/opt/keys/controller_keys/${ec2_cert}",
</pre>
Variables were reworked so not just `$var` but to `${var}` to be safe as #10146.
However changing the variables to namespace variables due to dynamic lookup
deprecation on 2.7.14 the following does not work.
<pre>
file { "/root/.ssh/${zpf-controller:ec2_cert}":
source => "/opt/keys/controller_keys/${zpf-controller:ec2_cert}",
</pre>
Errors with the following:
<pre>
May 10 16:19:51 zpf-controller-dev-1-10g-ruk puppet-master[20240]: Syntax error
at ':'; expected '}' at /etc/puppet/modules/zpf/manifests/init.pp:264 on node
zpf-controller-dev-2-512m-c4l
</pre>
So the variables are not being interpolated in the curly brackets.
However this does work.
<pre>
file { "/root/.ssh/$zpf-controller:ec2_cert":
source => "/opt/keys/controller_keys/$zpf-controller:ec2_cert",
</pre>
Does this mean that you cannot "curly bracket" namespace variables? Is this a
bug or another **significant** change in the variable interpolation changes
that come with 2.7.x?
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-bugs?hl=en.