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

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}

   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.

Thanks Henrik!  We're probably still a few weeks from upgrading to 3.7.x,
but when we do, getting our code ready for the future parser is also on
the list of things to do.

I had been planning on just temporarily disabling our entire pre-commit
hook, but since I've needed to use this in a couple of defines now, I did
end up going the route that Denmat suggested in a separate email, and just
used --no-only_variable_string-check with the other lint flags we're
passing to puppet-lint.

I appreciate your response and insight regarding this!

Tim
--
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.1411131109390.6400%40dogbert.cc.ndsu.NoDak.edu.
For more options, visit https://groups.google.com/d/optout.

Reply via email to