可有人請看看下面的代碼塊,讓我知道什麼是錯在這廚師配方:語法錯誤,意想不到的tIDENTIFIER,期待「:」
%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
你打算用'%w「#{zookeeper_ensemble}」''做什麼?在Ruby中,像''#{ip}「'通常與'ip'完全相同,或者更正式地說'ip.to_s',如果您擔心轉換爲字符串的話。這是貨運邪教反patttern看到單一的字符串插入像普遍。 – tadman 2014-10-17 16:15:11
我也很確定'node ['ipaddress']?(「#{ip}」)'是不是有效的Ruby,並且從那裏語法被破壞,所以你可能想要修復這個排隊。我期望'node ['ipaddress']。x?(...)'其中'x?'是一種方法,或者是'node ['ipaddress']? (...):(......)如果它是三元組的一部分。 – tadman 2014-10-17 16:19:21
感謝您的編輯和評論。我想要做的是創建包含少量IP地址的數組屬性,並在我的配方中讀取這些IP地址,並創建一個包含ipaddress數組索引的文件myid。 – Salim 2014-10-18 13:06:17