Chef-client –local-mode 返回零长度文件

Chef-client –local-mode 返回零长度文件

由于我最近发现 chef-solo 版本 12 存在问题,我将从 chef-solo 切换到 chef-client -z (--local-mode),以便在我的计算机上运行 chef。在我的其中一本食谱中,我有一个地方正在从食谱的“文件”子目录中下载一个 499 MB 的 gzip 压缩 tar 文件,然后立即提取该文件。代码如下:

# Retrieve and extract the classic.tgz file
cookbook_file '/usr/local/src/classic.tgz' do
  source 'opt/webdocs/classic.tgz'
  backup false
  owner "root"
  group "root"
  mode 0644
  notifies :run, "execute[untar-classic.tgz]", :immediately
end
execute 'untar-classic.tgz' do
  action :nothing
  command '/bin/tar xmzf /usr/local/src/classic.tgz'
  cwd '/opt/webdocs'
  user "apache"
  group "apache"
end

当它在 chef-client 中运行时,它会给出以下输出:

  * cookbook_file[/usr/local/src/classic.tgz] action create
    - create new file /usr/local/src/classic.tgz
    - update content in file /usr/local/src/classic.tgz from none to e3b0c4
    (no diff)
    - change mode from '' to '0644'
    - change owner from '' to 'root'
    - change group from '' to 'root'
  * execute[untar-classic.tgz] action run

    ================================================================================
    Error executing action `run` on resource 'execute[untar-classic.tgz]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '2'
    ---- Begin output of /bin/tar xmzf /usr/local/src/classic.tgz ----
    STDOUT: 
    STDERR: gzip: stdin: unexpected end of file
    /bin/tar: Child returned status 1
    /bin/tar: Error is not recoverable: exiting now
    ---- End output of /bin/tar xmzf /usr/local/src/classic.tgz ----
    Ran /bin/tar xmzf /usr/local/src/classic.tgz returned 2

    Resource Declaration:
    ---------------------
    # In /home/vagrant/.chef/local-mode-cache/cache/cookbooks/dcom-apache2/recipes/install_common.rb

    113: execute 'untar-classic.tgz' do
    114:   action :nothing
    115:   command '/bin/tar xmzf /usr/local/src/classic.tgz'
    116:   cwd '/opt/webdocs'
    117:   user "apache"
    118:   group "apache"
    119: end
    120: 

    Compiled Resource:
    ------------------
    # Declared in /home/vagrant/.chef/local-mode-cache/cache/cookbooks/dcom-apache2/recipes/install_common.rb:113:in `from_file'

    execute("untar-classic.tgz") do
      action [:nothing]
      retries 0
      retry_delay 2
      default_guard_interpreter :execute
      command "/bin/tar xmzf /usr/local/src/classic.tgz"
      backup 5
      cwd "/opt/webdocs"
      group "apache"
      returns 0
      user "apache"
      cookbook_name "dcom-apache2"
      recipe_name "install_common"
    end


Running handlers:
[2014-12-22T19:54:54+00:00] ERROR: Running exception handlers
Running handlers complete
[2014-12-22T19:54:54+00:00] ERROR: Exception handlers complete
[2014-12-22T19:54:54+00:00] FATAL: Stacktrace dumped to /home/vagrant/.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 2 resources updated in 1105.166057953 seconds
[2014-12-22T19:54:55+00:00] ERROR: execute[untar-classic.tgz] (dcom-apache2::install_common line 113) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '2'
---- Begin output of /bin/tar xmzf /usr/local/src/classic.tgz ----
STDOUT: 
STDERR: gzip: stdin: unexpected end of file
/bin/tar: Child returned status 1
/bin/tar: Error is not recoverable: exiting now
---- End output of /bin/tar xmzf /usr/local/src/classic.tgz ----
Ran /bin/tar xmzf /usr/local/src/classic.tgz returned 2
[2014-12-22T19:54:55+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

我正在 vagrant box(运行 Ubuntu 14.04)中测试此代码,当我登录到 VM 时,问题显而易见。该文件 /usr/local/src/classic.tgz 没有下载,即使 Chef 中没有抛出错误代码(Chef 尝试运行 untar 命令时会抛出 Chef 错误)。该文件在那里,但长度为零:

$ ls -l /usr/local/src/classic.tgz
-rw-r--r-- 1 root root 0 Dec 22 19:54 /usr/local/src/classic.tgz

我猜测该问题是 chef-zero 服务器超时,当 chef-client 使用 --local-mode 标志运行时,该服务器在后台运行,但我无法找到如何配置 chef-zero 服务器(我假设这是“chef-client --local-mode”的工作方式)。

请给我指出正确的方向。

谢谢!

RB狼

答案1

您可以通过从 chef repo 文件夹chef-client -z运行来独立运行服务器。然后您可以使用诸如检查清单是否正确之类的东西。500MB 绝对是chef-zeroknife cookbook show出色地超过文件大小,我建议通过 进行传输cookbook_file。我会将该文件存储在某个 Web 服务器上(可能是 S3),然后使用remote_file(或s3_file)下载它。这样会更安全,性能也会更好,Chef Server 使用的书架服务器并非为实现最大文件服务性能而设计的。

相关内容