2017-02-17 7 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アクセスを持っていけない環境の中でランダムに起こるので、私はこのエラーをキャッチし、より詳細な情報を提供するために、シェフのレシピを改善したいです

    ターゲットディレクトリのtar.gzファイルの
  1. サイズと作成された日付
  2. 権限
  3. 012:のようなエラーメッセージが表示さ

複雑なシェフの実行で表示されるのは(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 
のようなものを追加することができます
関連する問題