On 2014-07-11 23:43, Tim Mooney wrote:
In regard to: [Puppet Users] Re: creating hashes from other hashes,
Luke...:

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

Not so much a bug as an unessesary constraint.
This is changed in Puppet 4.0 (and when using --parser future in late 3x releases).

i.e. this then works:
apply --parser future -e '$x = hello notice({$x => world})'
Notice: Scope(Class[main]): {hello => world}


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


In 3x, the keys must be strings, but the $name is a string. What is not allowed is to have hash keys that are expressions (such as a variable expression).

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

Lint is simply complaining too much. There are several reasons for interpolating a single variable either as "$x", or "${x}" - one such reason is the constraint on hash keys, another is to force numeric to string conversion - say $x = 2 + 3 which makes $x not be a string but an Integer, some functions / uses does not do well when they receive an Integer instead of a String, and it must be transformed to a string, either via interpolation, or by calling the printf function.

So, while you in general do not have to do single variable interpolation, link is wrong in complaining about it everywhere. You could perhaps trick it by doing "${"$x"}" which is an interpolation of an interpolation :-)

Yet another option is to call the printf function in the interpolation expression.

Hope that helps explain why it does not work and how you can work around it until Puppet 4.0.0 comes out.

Regards
- henrik



--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
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/m3jvtn%24jnl%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to