In regard to: [Puppet Users] Re: creating hashes from other hashes, Luke...:

Huh, at first glance that to me looks like a parser bug.

That's what I was thinking too.

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:

Ok, thanks.  Unfortunately, we have puppet-lint hooked into our pre-commit
hook, and puppet-lint objects to a variable that is enclosed in double
quotes for no reason:

  WARNING: string containing only a variable on line 39
  WARNING: variable not enclosed in {} on line 39

I even tried doing this, to get around puppet-lint:

    $my_key = strip(" ${name } ")
    $new_pool = {
      $my_key => $fpm_pool,
    }

Still no joy, as now the parser objects to $my_key.  This really does
seem like a bug in the parser.

It looks like I'm going to have to temporarily disable our pre-commit
hook, and check in the code using "$name".

Thanks again Luke, your insight on this is much appreciated!

Tim


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




--
Tim Mooney                                             tim.moo...@ndsu.edu
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/alpine.SOC.2.11.1411071622310.23044%40dogbert.cc.ndsu.NoDak.edu.
For more options, visit https://groups.google.com/d/optout.

Reply via email to