Huh, at first glance that to me looks like a parser bug. Now that I think more on it I seem to recall this coming up before. The $name of a Defined Type is not of type String, and Puppet Hash keys are always strings, according to the docs:
https://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#hashes This code works, explicitly enclosing $name in a string: define foo::bar ( $stuff = {}, ) { $new_hash = {"$name" => $stuff} } class foo { foo::bar { 'somevalue': stuff => { 'one' => 'doesnt_matter', 'two' => 'doesnt_matter', } } } include foo On Thursday, November 6, 2014 10:04:00 PM UTC, Tim.Mooney wrote: > > > All- > > We're using puppet (opensource) 3.4.2 master and clients. We've been > using puppet a few years, including create_resources, but this is my > first foray into creating complicated nested hashes. > > I've boiled the problem I'm running into down to this example: > > $ cat /tmp/foo.pp > class foo { > foo::bar { 'somevalue': > stuff => { > 'one' => 'doesnt_matter', > 'two' => 'doesnt_matter', > } > } > } > > define foo::bar ( > $stuff = {}, > ) { > > # > # not valid: fails with a parser validation error on the key $name: > # > # Error: Could not parse for environment production: Syntax error at > # 'name'; > # expected '}' at /tmp/foo.pp:21 > # > $new_hash = { > $name => $stuff, > } > > # > # this works, using a constant key > # > $new_hash = { > 'a_constant' => $stuff, > } > } > > > This comes from a larger, more complicated example, but what I'm trying to > do is > > - take a hash ($stuff) that has all the parameters I need > - create a new hash with a single key that's the $name/$title for the > define, > and a value that contains the hash $stuff that I was passed. > > As you might guess, this is to make $new_hash suitable for passing > to create_resources. > > Is there some other way to create a new hash, give it a single top-level > key that is a variable, and assign a separate (passed-in as a parameter) > hash as the value for that key? I would be fine with using stdlib::merge, > but I don't see any obvious way to accomplish this task with stdlib::merge > either. > > Thanks, > > Tim > -- > Tim Mooney tim.m...@ndsu.edu > <javascript:> > Enterprise Computing & Infrastructure 701-231-1076 > (Voice) > Room 242-J6, Quentin Burdick Building 701-231-8541 (Fax) > North Dakota State University, Fargo, ND 58105-5164 > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/55af70aa-0917-4f89-8431-420148c27279%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.