berkshelf / vagrant-berkshelf

A Vagrant plugin to add Berkshelf integration to the Chef provisioners
Other
378 stars 100 forks source link

Can't Find Gem Berkshelf #318

Open gbonk opened 7 years ago

gbonk commented 7 years ago

I'm trying to perform a fresh install with the latest of everything and using the Chocolatley provisioner on a windows 7 machine.

I have....

  1. Installed Chocolatley, 0.10.5
  2. Installed Vagrant, 1.9.5, via Chocolatley
  3. Installed ChefDK, 1.3.43, via Chocolatley

Chef Development Kit Version: 1.3.43 chef-client version: 13.0.118 delivery version: master (dd319aa632c2f550c92a2172b9d1226478fea997) berks version: 5.6.4 kitchen version: 1.16.0

  1. Installed the Vagrant Berkshelf plugin

$ vagrant plugin list vagrant-berkshelf (5.1.1) vagrant-share (1.1.8, system) vagrant-vbguest (0.14.2)

Here is my Vagrant File..


Vagrant.configure("2") do |config|

  config.berkshelf.enabled = true

  config.vm.box = "ubuntu/xenial64"

  config.vm.provision :chef_solo do |chef|
    chef.add_recipe "apache2"
  end
end

and my Berksfile

source "https://supermarket.chef.io"

cookbook 'apache2'

When I vagrant up, I receive the following warning and error...

$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... The following berks command failed to execute:

C:\opscode\chefdk\embedded\bin/berks.BAT --version --format json

The stdout and stderr are shown below:

stdout:
stderr: Ignoring wdm-0.1.1 because its extensions are not built.  Try: gem pristine wdm --version 0.1.1

C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.3.0/rubygems.rb:270:in find_spec_for_exe': can't find gem berkshelf (>= 0.a) (Gem::GemNotFoundException) from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.3.0/rubygems.rb:298:inactivate_bin_path' from C:/opscode/chefdk/embedded/bin/berks:22:in `

'

gbonk commented 7 years ago

I put some 'puts' in the area that the exception is thrown. Don't know if it helps but it appears to be that berkshelf is not on the 'classpath' even though it is when I list it, and I had installed it with a 'gem install'

    Gem::Specification.each do | spec|
        puts spec
    end

AND

puts Gem.path

Results in: C:/HashiCorp/Vagrant/embedded/gems

$ which ruby /c/opscode/chefdk/embedded/bin/ruby

$ which gem /c/opscode/chefdk/embedded/bin/gem

$ gem list --local | grep berk berkshelf (5.6.4, 5.6.3, 5.6.0, 5.5.0) berkshelf-api-client (3.0.0) vagrant-berkshelf (5.1.1)

gbonk commented 7 years ago

Further investigation shows that, In Ruby, if the GEM_HOME environment variable is set then that OVERRIDES the "Gem.default_dir" path for Gems.

Putting a "puts ENV" at the beginning of C:\opscode\chefdk\embedded\bin\berks.rb shows that when U run a vagrant up "GEM_PATH": "C:\HashiCorp\Vagrant\embedded\gems" BUT when I run ruby /c/opscode/chefdk/embedded/bin/berks --version --format json from my git bash, the command runs fine and in my Shell env there is no GEM_PATH set.

I'm not sure then if this is a Vagrant issue or a Plugin issue. Tho I am going to check in with Vagrant as well

gbonk commented 7 years ago

In Vagrant-Berkshelf/helpers.rb there is a call to "Vagrant::Util::Env.with_clean_env do".

I'm not sure if there is something here in the beginning of the plugin that would work better ?

gbonk commented 7 years ago

Yes, if I update "~.vagrant.d\gems\2.2.5\gems\vagrant-berkshelf-5.1.1\lib\vagrant-berkshelf\helpers.rb" and add the following at line 62

ENV.delete("GEM_HOME" )
ENV.delete("GEM_PATH" )

Everything works fine

xi-ao commented 7 years ago

Thanks so much @gbonk, I've been stuck on this issue for months now. Thought it was a dark incompatibility between ChefDK, Vagrant and Berkshelf on particular conditions but it's far more simpler than that. I can finally use Vagrant again on Archlinux.

pbc commented 6 years ago

Based on what @gbonk suggested , there is a less invasive hack which might work for some people.

Just add these lines at the top of your Vagrantfile :

  ENV["GEM_PATH"] = nil
  ENV["GEM_HOME"] = nil

It works for me while using rbenv to manage my ruby versions.