0

我希望使用基于属性/default.rb 文件中声明的主机数的模板将“server.x=hostname:Quorom_Port:Election_Port”值写入zoo.cfg

default['zookeeper']['servers'] = ["hostname1", "hostname2", "hostname3"]
default['zookeeper']['follower_port'] = 2888
default['zookeeper']['election_port'] = 3888

对于上述属性,应使用模板将以下值自动写入 zoo.cfg 文件:

server.1= hostname1:2888:3888
server.2= hostname2:2888:3888
server.3= hostname3:2888:3888

请让我知道该怎么做?

4

1 回答 1

0
<%- 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 %>

上面这段代码解决了这个问题。

于 2015-02-23T12:02:55.087 回答