我的节点上有一个可选属性。我希望我的模板只在该属性存在时才设置特定值:
<% if node['haproxy']['server']['backup'] %>
server <%= node['haproxy']['server']['backup']['hostname'] %> <%= node['haproxy']['server']['backup']['ipaddress'] %>:<%= node['mysql']['port'] %> weight 1 maxconn 100 check
<% end %>
这对我来说很好,但是当我运行它时,我收到以下错误:
Chef::Mixin::Template::TemplateError
------------------------------------
no implicit conversion of String into Integer
如何让这个工作正常,以便Chef识别属性是否已设置?
答案 0 :(得分:3)
尝试
<% if node['haproxy']['server'].attribute?('backup') %>