chef provisioner & Chef::Config[:file_cache_path] race condition ?

1,207 views
Skip to first unread message

jonbarber

unread,
Jul 18, 2013, 11:00:56 AM7/18/13
to vagra...@googlegroups.com
Hi,

I've just upgraded to Vagrant 1.2.4, and at the same time I took the opportunity to move our Vagrantfile to the new "2" layout, so I can't say for sure what has caused this issue...

The opscode Java cookbook we've used for ages has suddenly started failing, and it looks like it's down to the chef cache directory (Chef::Config[:file_cache_path]) not being created before the cookbooks are run :

remote_file[/var/chef/cache/jre-6u31-linux-i586.bin] (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/providers/ark.rb line 116) had an error: Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /var/chef/cache does not exist.


The line of code referenced above is here :

      r = remote_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do
        source new_resource.url
        checksum new_resource.checksum
        mode 0755
        action :nothing
      end

When I set the chef log level to debug I see these lines right at the very end after the cookbooks have failed :

[2013-07-18T14:02:07+00:00] ERROR: Running exception handlers
[2013-07-18T14:02:07+00:00] ERROR: Exception handlers complete
[2013-07-18T14:02:07+00:00] DEBUG: Creating directory /var/chef
[2013-07-18T14:02:07+00:00] DEBUG: Creating directory /var/chef/cache

So it looks like the directory is created after the cookbooks have been executed - less than ideal. If after the failure I run vagrant provision it works fine, as the directory has now been created.

Is this a Vagrant issue, or is it a chef solo issue ? Or am I doing something stupid ? Gist with the Vagrantfile at https://gist.github.com/jonbarber/6b6b9e1f06fbc902c870#file-vagrantfile

Jon.


Ryan Jarvis

unread,
Jul 24, 2013, 9:39:42 AM7/24/13
to vagra...@googlegroups.com
I'm getting this exact same failure except trying to build the Opscode Python cookbook which has previously been working.

I am also on Vagrant 1.2.4.  I just created a minimal vagrantfile that does nothing but install Python and it fails.  I am really hoping someone could take a look at this soon and let us know where the issue lies.

Thanks.

John Nadeau

unread,
Jul 25, 2013, 10:01:18 AM7/25/13
to vagra...@googlegroups.com
Ditto, on 1.2.4 with a custom redis cookbook using the cache directory to save the redis tar.

John

Milos Gajdos

unread,
Aug 19, 2013, 3:30:28 PM8/19/13
to vagra...@googlegroups.com
I got around this problem like so:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# We'll mount the Chef::Config[:file_cache_path] so it persists between
# Vagrant VMs
host_cache_path = File.expand_path("../.cache", __FILE__)
guest_cache_path = "/tmp/vagrant-cache"

# ensure the cache path exists
FileUtils.mkdir(host_cache_path) unless File.exist?(host_cache_path)

Vagrant.configure("2") do |config|
  config.vm.hostname = "gc-sentinel-berkshelf"

  config.vm.box = "ubuntu-12.04"

  # this requires vagrant-omnibus plugin to be installed
  config.omnibus.chef_version = "10.24.4"

  # Assign this VM to a host-only network IP, allowing you to access it
  # via the IP. Host-only networks can talk to the host machine as well as
  # any other machines on the same network, but cannot be accessed (through this
  # network interface) by any external networks.
  config.vm.network :private_network, ip: "33.33.33.10"

  config.ssh.max_tries = 40
  config.ssh.timeout   = 120

  # Enabling the Berkshelf plugin. To enable this globally, add this configuration
  # option to your ~/.vagrant.d/Vagrantfile file
  config.berkshelf.enabled = true

  # requires vagrant-hostmanager plugin to be intalled
  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.hostmanager.ignore_private_ip = false
  config.hostmanager.include_offline = true

  # run hostmaster before chef_solo provisioning
  config.vm.provision :hostmanager
  config.vm.provision :chef_solo do |chef|
    chef.log_level = "debug"
    chef.provisioning_path = guest_cache_path
    chef.data_bags_path = "../data_bags"
    chef.run_list = [
        "recipe[apt]",
        "recipe[gc_sentinel::default]"
    ]
  end

  config.vm.synced_folder host_cache_path, guest_cache_path
end

Antoine Lyset

unread,
Sep 5, 2013, 9:51:55 AM9/5/13
to vagra...@googlegroups.com
Hi,

I get the same problem, and try your solution. It seems to work well. But I think we need a more "reliable" fix. Anyone interested ?

Antoine Lyset

unread,
Sep 5, 2013, 9:53:37 AM9/5/13
to vagra...@googlegroups.com
Ok, in fact it just crashed again. Nevermind. I got the same problem...
Reply all
Reply to author
Forward
0 new messages