我正在研究廚師食譜,我需要根據代碼的結果更新數據包中的某些信息。基本上我需要更新一個成功或失敗的數據包。如何捕捉廚師異常
的代碼看起來是這樣的:
begin
node[:fileDeploy].each do |f|
if f[:deploy]
cookbook_file "#{f[:subdirectory]}/#{f[:targetFilename]}" do
owner users['tomcatUser']
group users['tomcatGroup']
mode "0755"
cookbook node[:cookbookName]
source "#{f[:sourceFilename]}"
end
end
end
# Update data bag: succeeded
rescue Chef::Exceptions::FileNotFound => e
# Update data bag: failed
end
的問題是,即使有文件丟失,救援塊不excecuted和數據包不會隨之更新。 因此,當我在服務器上運行命令sudo chef-client時,它將以異常Chef::Exceptions::FileNotFound
結束,但它不會由rescue
塊處理。是否有意義?任何幫助?
您能否提供有關導致錯誤的信息。這可以幫助我們幫助您處理代碼。 – screenmutt