2014-01-27 104 views
3

我很新Chef。我有一個配方,安裝sendmail,它做我的配置。我注意到,Chef每次運行都會重新啓動服務。這是因爲我正在運行調用會話重新啓動的execute廚師執行塊

它看起來像這樣:

execute "hashAccess" do 
    command "makemap hash /etc/mail/access < /etc/mail/access" 
    notifies :restart, "service[sendmail]" 
end 

我需要的,如果更新了access文件時纔會調用它。

template "/etc/mail/access" do 
    source "access.erb" 
    mode "0644" 
    notifies :run, "execute[hashAccess]" 
end 

當文件更新時,execute被調用兩次。 兩種資源都在相同的配方,當我嘗試definehashAccess我得到一個錯誤

ERROR: Cannot find a resource for define on amazon version 2013.09 

如何使執行資源僅調用時運行?

回答

6

您應該將action :nothing添加到您的執行資源中。

execute "hashAccess" do 
    command "makemap hash /etc/mail/access < /etc/mail/access" 
    action :nothing 
    notifies :restart, "service[sendmail]" 
end 

這樣它不會被執行,除非被其他資源通知。

+0

謝謝!我知道它會很簡單... :) –

+1

謝謝@Draco Ater – Robert