2017-02-17 42 views
1

下面是一些嘗試將文件解壓到某個目錄的廚師代碼。如何使廚師資源執行中的錯誤消息更豐富?

該配方被稱爲從一些其他食譜深處,它失敗隨機

unless ::File.exists?(::File.join(node[:zookeeper][:install_dir], zk_basename)) 

    execute 'install zookeeper' do # <-- Line 57 
    user node[:zookeeper][:user] 
    cwd Chef::Config[:file_cache_path] 
    command "tar -C#{node[:zookeeper][:install_dir]} -zxf #{zk_basename}.tar.gz" 
    end 
end 

我看到的錯誤是:

Mixlib::ShellOut::ShellCommandFailed: execute[install zookeeper] (zookeeper::add line 57) had an error: 
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '2' . , 
FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[install zookeeper] (zookeeper::add line 57) had an error: 
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '2' . 

由於錯誤的環境中隨機發生我沒有SSH訪問,我想提高廚師的配方來抓住這個錯誤,並提供更多的細節在這樣的錯誤消息:

  1. 尺寸和tar.gz文件的目標目錄的
  2. 權限的創建日期

請注意,我必須將它們放入異常的錯誤消息中,因爲這是唯一可以看到(無ssh訪問)的複雜廚師跑步。

回答

0

您可以添加這樣的事情

log 'log_important_bits' do 
    message lazy { 
    the_dir = ::File.stat(node[:zookeeper][:install_dir]) 
    the_file = ::File.stat(::File.join(node[:zookeeper][:install_dir], zk_basename)) 
    "file.size = #{the_file.size} ... put whatever you want here" 
    } 
    level :error # So you'll always see it 
end 
相關問題