2017-02-17 89 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 
相关问题