I'm using puppet to provide a set of constants for a ruby program. I need to provide an array of hostnames over which my program will iterate.
In the bash script I was using before this, I simply had as a puppet variable
hosts => "host1,host2"
which I provided to the bash script as
HOSTS=<%= hosts %>
obviously this won't quite work for ruby - I need it in the format
hosts = ["host1","host2"]
since
p hosts
and
puts my_array.inspect
provide the output
["host1","host2"]
I was hoping to use one of those. Unfortunately, I cannot for the life of me figure out how to make that work. I've tried each of the following:
<% p hosts %>
<% puts hosts.inspect %>
I found somewhere where they indicated I'd need to put "function_" in front of function calls...that doesn't seem to work. I've settled on an iterative model:
[<% hosts.each do |host| -%>"<%=host%>",<% end -%>]
this works, giving me
["host1","host2",]
but the trailing comma feels sloppy. the whole thing feels sloppy. Does anyone have a better way? Or is what I've done the best option?