有人可以看看下面的代码块,让我知道这个
有什么问题%w"#{zookeeper_ensemble}".each_with_index do |ip, index|
if node['ipaddress']?("#{ip}")
template "#{zookeeper_data}/myid" do
source "myid.erb"
owner zookeeper_user
group zookeeper_user
variables(
:myid=> "#{index}"
)
end
end
end
我收到以下错误
SyntaxError
-----------
/root/.chef/local-mode-cache/cache/cookbooks/zookeeper/recipes/default.rb:69: syntax error, unexpected tIDENTIFIER, expecting ':'
template "#{zookeeper_data}/myid" do
^
/root/.chef/local-mode-cache/cache/cookbooks/zookeeper/recipes/default.rb:78: syntax error, unexpected keyword_end, expecting end-of-input
答案 0 :(得分:1)
你可能意味着什么:
zookeeper_ensemble.each_with_index do |ip, index|
if node['ipaddress'] == ip
template "#{zookeeper_data}/myid" do
source "myid.erb"
owner zookeeper_user
group zookeeper_user
variables myid: index
end
end
end
答案 1 :(得分:1)
解决了我自己 当然,@ Codrenger的答案给了我方向。感谢
default['zookeeper']['cluster_ips'] = {'1.1.1.1' => 1, '2.2.2.2' => 2}
.
.
.
node['zookeeper']['cluster_ips'].each do |ip, id|
if node["ipaddress"] == ip
template "#{zookeeper_data}/myid" do
source "myid.erb"
owner zookeeper_user
group zookeeper_user
variables myid: id
end
end
end