Ask Your Question

hiera dealing with undefined variables in erb templates

asked 2014-08-12 05:16:48 -0500

jaksky gravatar image


I start using hiera for environment or machine specific variables but I am facing an issue when variable is not found nowhere. Desired behaviour is that shouldn't be included into template. I did following: In my manifest code


and in erb template I have:

<% if !@yarn_app_mapreduce_am_command_opts.nil? %>   
    <value><%= @yarn_app_mapreduce_am_command_opts %></value>
<%end %>

According to the documentation here safest is to test on nil. I tried several variants but non of them worked.

Could someone help?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-08-12 16:19:07 -0500

timelord gravatar image

Maybe a workaround:

$yarn_app_mapreduce_am_command_opts=hiera('', '')

$yarn_app_mapreduce_am_command_opts_real = $yarn_app_mapreduce_am_command_opts ? {
   ''      => nil,
   nil     => nil,
   default => $yarn_app_mapreduce_am_command_opts,

<% if !@yarn_app_mapreduce_am_command_opts_real.nil? %>   
    <value><%= @yarn_app_mapreduce_am_command_opts %></value>
<%end %>
edit flag offensive delete link more

answered 2014-08-12 22:54:23 -0500

ramindk gravatar image

I just set undef and then only check for the var. Seems to work on my system.


define redis::server (
  $password     = undef,
  $port         = '6379',
  $bind         = '',
  $master       = 'localhost',
  $master_port  = $port
) { }


# blah blah other stuff
<% if @password -%>
masterauth <%= @password %>
<% end -%><% end -%>
edit flag offensive delete link more


I would say that you are testing a bit different use case. Seems that hiera function is causing the problem in this case :-)

jaksky gravatar imagejaksky ( 2014-08-13 02:25:35 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-08-12 05:16:48 -0500

Seen: 2,177 times

Last updated: Aug 12 '14