Ask Your Question

Help on ERB teample

asked 2015-08-12 08:47:19 -0600

updated 2015-08-12 11:37:06 -0600

GregLarkin gravatar image

Hi I am new to puppet/ruby . Appreciate if someone help me on this.

<%  if"host1", 636) and"host2", 1636)  %>
host xxxx
port 636

<% else -%>
host yyyy
port 389

<% end %>
<% end %>

Above is sample code of my ERB template..I wana check if port is open for specific hosts before doing anything. The problem is when the port is not opened it raises Connection refused error and hence it failing puppet apply. Can't I catch exception and exit if exception is raised? Also how to define timeout?

 rescue Errno::ECONNREFUSED => e

I tried above code but it didnt work.

Can someone suggest pls?

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-08-12 16:30:34 -0600

fura gravatar image


I think you want something like this:

<% begin
  Timeout.timeout(10) do
      if"host1", 636) and"host2", 1636) %>
host xxx
port 636
      <% else %>
host yyy
port 389
      <% end
    rescue Errno::ECONNREFUSED
      raise Puppet::Error, "host unreach" %>
  <% end
  rescue Timeout::Error
    raise Puppet::Error, "Timeout"
end %>

but this code never go to else

edit flag offensive delete link more

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: 2015-08-12 08:47:19 -0600

Seen: 180 times

Last updated: Aug 12 '15