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}
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/