How to get an array index in erb template in puppet
Question
I need to be able to generate following content of the file (for zookeeper installation):
server.1=$zk.server1.full.hostname:2888:3888
server.2=$zk.server2.full.hostname:2888:3888
server.3=$zk.server3.full.hostname:2888:3888
when I have an array of server hostnames (example shows # of servers = 3). I tried something like following:
<% @regionserver_list.each do |this_server| -%>
server. =<%= this_server %>:2888:3888
<% end -%>
That seems not correct as and I am struggling with getting an array index (need to start from 1). The point here is that the list of servers will be variable so I cannot use workaround with putting fixed template here for time being. I am stuck on this, can someone help?
Thx
Solution
This works:
<% @quorumserver_list.to_enum.with_index(1).each do |this_server, idx| -%>
<%= "server.#{idx}=#{this_server}:2888:3888" %>
<% end -%>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow