2016-06-24 74 views
1

我的節點上有一個可選屬性。我想如果屬性存在我的模板,只設置一個特定值:廚師模板如果屬性存在

<% 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 

哪有我得到這個工作,所以廚師認識到,如果屬性設置?

+0

原來我需要使用的對象,而不是陣列。 – user3063045

回答

2

嘗試

<% if node['haproxy']['server'].attribute?('backup') %>