我在厨师模板中有以下代码,但在上传到厨师服务器时会出错。我该如何解决?
<%
contents_hash = File.read('/tmp/cluster_hash')
neoservers_hash = JSON.parse(contents_hash)
-%>
<% "#{neoservers_hash}".each_pair do |id, ipaddress| %>
<%= "server.#{id}=#{ipaddress}:2888:3888" %>
<% end %>
当我尝试上传食谱时,出现以下错误:
$ knife cookbook upload neo4j -E development
Uploading neo4j [0.1.0]
FATAL: Erb template templates/default/coord.cfg.erb has a syntax error:
FATAL: -:7: syntax error, unexpected tIDENTIFIER, expecting '}'
FATAL: _buf << ( "server.#{id}=#{ipaddress}:2888:3888" ).to_s; _buf << '
FATAL: ^
FATAL: -:8: unterminated string meets end of file
答案 0 :(得分:1)
你在这一行中有一个奇怪的语法:
<% "#{neoservers_hash".each_pair do |id, ipaddress| %>
您似乎尝试将字符串评估与neoserver_hash
变量一起使用,这不会真正起作用,因为neoserver_hash
是哈希而不是字符串。你也错过了大括号。相反,您可能希望完全摆脱字符串评估并使用以下内容:
<% neoservers_hash.each_pair do |id, ipaddress| %>