- From: AJ Christensen <
>
- To: chef <
>
- Subject: [chef] Re: Templates don't fail when values are missing
- Date: Tue, 16 Apr 2013 07:45:15 +1200
In ruby, Hash[nil] => nil; so, explicitly bind your hash keys to
'variables' in the template and then check for presence of the ivar.
An alternate workaround: <%= if @property.key?('foobar') %>
Cheers,
AJ
On 16 April 2013 06:48, Peter Loron
<
>
wrote:
>
I have a large (hundreds of properties, dozens of templates) set of
>
templates I'm porting from Nant to Chef. The properties in the old system
>
are scattered across multiple files and while aggregating the properties
>
into data bags and adjusting the templates, I have missed some values.
>
>
The call in the recipe to merge each template with the properties from the
>
data bags works, but values that are not present in the hash are simply
>
empty in the generated template. The substitution fails silently.
>
>
For example, if I have this in the template:
>
>
<foobar value="<%= @property['foobar'] %>" />
>
>
… and the 'foobar' key/value pair is not present, I wind up with this in
>
the generated file:
>
>
<foobar value="" />
>
>
>
>
Is there any way to get Chef to throw a warning or error in this case?
>
>
Thanks.
>
>
-Pete
Archive powered by MHonArc 2.6.16.