I want "server.x=hostname:Quorom_Port:Election_Port" value to be be written to zoo.cfg using a template based on number hosts declared in attributes/default.rb file
default['zookeeper']['servers'] = ["hostname1", "hostname2", "hostname3"]
default['zookeeper']['follower_port'] = 2888
default['zookeeper']['election_port'] = 3888
For the above attributes, the following values should be automatically written in zoo.cfg file using a template:
server.1= hostname1:2888:3888
server.2= hostname2:2888:3888
server.3= hostname3:2888:3888
Please let me know how to do this?
<%- if node['zookeeper']['servers'] %>
<%- node['zookeeper']['servers'].each_with_index do |host, idx| %>
server.<%= idx+1 %>=<%= host %>:<%= node['zookeeper']['follower_port']%>:<%= node['zookeeper']['election_port']%>
<%- end %>
<%- end %>
The above piece of code solved the problem.