Search code examples
vagrantberkshelfvagrant-plugin

Error when doing "vagrant provision" with berkshelf


I am using Windows with vagrant and chefdk installed. I can successfully vagrant up a VM without problem. So my next thing to do is to add provisioning feature to it. I downloaded some cookbooks and created a Berksfile to solve the dependencies, however when I run vagrant provision, it shows me the following error:

C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/fileutils.rb:245:in `mkdir': No such file or directory - K: (Errno::ENOENT)
    from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/fileutils.rb:245:in `fu_mkdir'
    from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/fileutils.rb:219:in `block (2 levels) in mkdir_p'
    from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/fileutils.rb:217:in `reverse_each'
    from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/fileutils.rb:217:in `block in mkdir_p'
    from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/fileutils.rb:203:in `each'
    from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/fileutils.rb:203:in `mkdir_p'
    from C:/Users/victorwong/.vagrant.d/gems/gems/vagrant-berkshelf-4.0.3/lib/vagrant-berkshelf/action/load.rb:40:in `mkshelf'
    from C:/Users/victorwong/.vagrant.d/gems/gems/vagrant-berkshelf-4.0.3/lib/vagrant-berkshelf/action/load.rb:23:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builtin/env_set.rb:19:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/Users/victorwong/.vagrant.d/gems/gems/vagrant-berkshelf-4.0.3/lib/vagrant-berkshelf/action/check.rb:18:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builtin/handle_box.rb:56:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builder.rb:116:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in `block in run'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/util/busy.rb:19:in `busy'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in `run'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builtin/call.rb:53:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builder.rb:116:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in `block in run'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/util/busy.rb:19:in `busy'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in `run'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:214:in `action_raw'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:191:in `block in action'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/environment.rb:516:in `lock'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:178:in `call'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:178:in `action'
    from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/batch_action.rb:82:in `block (2 levels) in run'

It tells me it cannot mkdir on K: as it does not exist. It was the drive of an external drive which I disconnected right now. I have no idea why K: comes out here. This error does not appear when I do not enable berkshelf, so it might be related to berkshelf.

My Berksfile:

source "https://supermarket.getchef.com"

cookbook 'java', path: 'chef-script/cookbooks/java'

My Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# ...
  config.omnibus.chef_version = :latest
  config.berkshelf.enabled=true

  config.vm.provision "chef_solo" do |chef|
    chef.cookbooks_path = "chef-script/cookbooks"
    chef.add_recipe "java"
  end
end

So, 2 questions:

Q1. how can I force it to C: instead of K:;

Q2. why does it point to K: by default?


Solution

  • I finally found the reason behind, hope someone would feel useful. It is actually very simple. The K: comes from the environmental variables HOMEDRIVE.

    By typing command in CMD of Windows

    SET
    

    A list of runtime environmental variables comes out. If there is something look like this

    HOMEDRIVE=K:
    

    or whatever weird drive letter, then bingo! Now to change the value, simply

    SET HOMEDRIVE=C:
    

    Then things work like a charm.

    Still I have no idea who and when it set this runtime variable. But anyway it solved my problem.