Hi,

I have the following code snippet

node default {
    # $var_a   .. is undefined
    $var_b = hiera("var_b", undef)
    $var_c = undef

    file { "/var/tmp/foo.txt": content => inline_template("

<% if @var_a %>
var_b = <%= @var_a %>
<% else %>
<% info(\"var_a is undefined\") %>
<% end -%>

<% if @var_b %>
var_b = <%= @var_b %>
<% else %>
<% info(\"var_b is undefined\") %>
<% end -%>

<% if @var_c %>
var_c = <%= @var_c %>
<% else %>
<% info(\"var_c is undefined\") %>
<% end -%>

"
), }
}

Applying it, will generate these two info messages.

Info: template[inline]: var_a is undefined
Info: template[inline]: var_c is undefined
var_b = 

What I would like puppet to do is to fail if template is referencing a 
variable which is not defined, without having to wrap it with 
if-else-fail()-end.

Another strange thing I've noticed that "undef" behaves differently if it 
is a default value for hiera lookup (see var_b vs var_c).

Actually, my code looks more like..

$var_a = hiera("var_a")
$var_b = hiera("var_b")
$var_c = hiera("var_c")
file {"..": content => template(hiera("tmpl_name")) }

That will fail if any variable a,b,c is undefined in hiera, no matter if it 
is used in template or not. I can rewrite it to

$var_a = hiera("var_a", undef)
$var_b = hiera("var_b", undef)
$var_c = hiera("var_c", undef)
file {"..": content => template(hiera("tmpl_name")) }

This will not fail even if variable used by the template is undefined. The 
value is quietly replaced by empty string.

In other words, I would like to delay the failure from hiera() lookup to 
the time when it is actually used in template. Can it be done without 
explicitly testing it with "if" inside template ?

Thanks,

BranoZ

PS: we are (or soon be) on puppet 3.2.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to