-1

I am switching from chef-solo to chef-client -z (--local-mode) for running chef on my machines because of an issue that I've seen recently with chef-solo in version 12. I have one spot in one of my cookbooks where I'm downloading a 499 MB, gzipped tar file from the 'files' subdirectory of the cookbook, then immediately extracting the file. The code follows:

# 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

When this runs in chef-client, it gives the following output:

  * 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)

I'm testing this code in a vagrant box (running Ubuntu 14.04) and when I login to the VM, the problem is evident. That file, /usr/local/src/classic.tgz, didn't download, even-though there was no error code thrown in Chef (the Chef error is thrown when Chef tries to run the untar command). The file is there, but it is zero-length:

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

I'm guessing that this issue is a time-out on the chef-zero server that is working behind the scenes when chef-client is run with the --local-mode flag, but I've been unable to find how to configure the chef-zero server (I'm assuming this is how 'chef-client --local-mode' works).

Please point me in the right direction.

Thanks!

RB Wolf

RBWolf
  • 1

1 Answers1

0

You can run the server independently of chef-client -z by running chef-zero from the chef repo folder. You can then use things like knife cookbook show to check that the manifest looks correct. 500MB is definitely well above the size of a file I would recommend delivering through a cookbook_file. I would store that file on a web server somewhere (possibly S3) and use a remote_file (or s3_file) to download it. That will be far less brittle and probably perform a lot better, the bookshelf server used by Chef Server is not designed for maximum file serving performance.

coderanger
  • 858
  • 4
  • 13