Ruby Chef Template DSL-如何从json加载哈希并迭代键和值

Ruby Chef Template DSL-如何从json加载哈希并迭代键和值,ruby,chef-infra,Ruby,Chef Infra,我在chef模板中有以下代码,但在上传到chef服务器时出错。我该如何解决 <% contents_hash = File.read('/tmp/cluster_hash') neoservers_hash = JSON.parse(contents_hash) -%> <% "#{neoservers_hash}".each_pair do |id, ipaddress| %> <%= "server.#{id}=#{ipaddress

我在chef模板中有以下代码,但在上传到chef服务器时出错。我该如何解决

<%
    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
$knife cookbook上传neo4j-E开发
上传neo4j[0.1.0]
致命错误:Erb template templates/default/coord.cfg.Erb有语法错误:
致命:-:7:语法错误,意外的tIDENTIFIER,应为“}”

致命:_buf您在这行中有一个奇怪的语法:

<% "#{neoservers_hash".each_pair do |id, ipaddress| %>

如果你纠正了这个错误,那就从根本上改变了你问题的前提。因为这个输入错误(以及错误的字符串计算)是导致错误的全部原因。错误是一样的。运行代码时它不是一个类型
<% neoservers_hash.each_pair do |id, ipaddress| %>