Issue #9374 has been updated by Brice Figureau.
James Turnbull wrote:
> Brice - this seems odd? Any ideas?
This works for me:
<pre>
class foo {
define bar ( $val ) {
notice("bar($val)")
}
}
$some_hash = { 'name' => "some_name" }
foo::bar { $some_hash['name']: }
</pre>
This correctly fails because the bar definition needs a val parameter:
<pre>
Must pass val to Foo::Bar[some_name] at
/Users/brice/devl/puppet/manifests/hashkey_as_namevar.pp:3 on node macbook.local
</pre>
And when the val parameter is given, I get:
<pre>
notice: Scope(Foo::Bar[some_name]): bar(yeah)
</pre>
This is on latest 2.7.x HEAD.
----------------------------------------
Bug #9374: Hash Members Cannot be Used in Resource Names and Throws Confusing
Error
https://projects.puppetlabs.com/issues/9374
Author: Brad Krane
Status: Needs More Information
Priority: Normal
Assignee: Brice Figureau
Category: language
Target version:
Affected Puppet version: 2.7.1
Keywords:
Branch:
The following snippet exhibits unexpected behavior.
<pre>
class foo {
define bar ( $val ) {
notice("bar($val)")
}
}
$some_hash = { 'name' => "some_name" }
foo::bar { $some_hash['name']: }
</pre>
The result of this is the very confusing and incorrect error message below:
<pre>
Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource
type foo::bar at puptest.pp:8 on node www-cms-dev
</pre>
What makes this especially odd and inconsistent is that the following works as
you would expect:
<pre>
$some_hash = { 'name' => "some_name" }
notice($some_hash['name'])
</pre>
So, a hash member is treated differently in the two cases contrary to the
principle of least surprise. In the former the member value is not "expanded"
and passed on to the resource as it's name as you would expect, but it is
"expanded" in the case of the notice example.
--
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.