Skip to content
This repository has been archived by the owner on Dec 26, 2017. It is now read-only.

Can't Find Gem Berkshelf #318

Open
gbonk opened this issue May 23, 2017 · 6 comments
Open

Can't Find Gem Berkshelf #318

gbonk opened this issue May 23, 2017 · 6 comments

Comments

@gbonk
Copy link

gbonk commented May 23, 2017

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:in activate_bin_path'
from C:/opscode/chefdk/embedded/bin/berks:22:in `

'

@gbonk
Copy link
Author

gbonk commented May 23, 2017

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

#<Gem::Specification name=bigdecimal version=1.2.8>
#<Gem::Specification name=builder version=3.2.3>
#<Gem::Specification name=childprocess version=0.6.3>
#<Gem::Specification name=domain_name version=0.5.20170404>
#<Gem::Specification name=erubis version=2.7.0>
#<Gem::Specification name=ffi version=1.9.18>
#<Gem::Specification name=gssapi version=1.2.0>
#<Gem::Specification name=gyoku version=1.3.1>
#<Gem::Specification name=hashicorp-checkpoint version=0.1.4>
#<Gem::Specification name=http-cookie version=1.0.3>
#<Gem::Specification name=httpclient version=2.8.3>
#<Gem::Specification name=i18n version=0.8.0>
#<Gem::Specification name=io-console version=0.4.5>
#<Gem::Specification name=json version=1.8.3>
#<Gem::Specification name=listen version=3.1.5>
#<Gem::Specification name=little-plugger version=1.1.4>
#<Gem::Specification name=log4r version=1.1.10>
#<Gem::Specification name=logging version=2.2.2>
#<Gem::Specification name=mime-types version=3.1>
#<Gem::Specification name=mime-types-data version=3.2016.0521>
#<Gem::Specification name=multi_json version=1.12.1>
#<Gem::Specification name=net-scp version=1.2.1>
#<Gem::Specification name=net-sftp version=2.1.2>
#<Gem::Specification name=net-ssh version=4.1.0>
#<Gem::Specification name=netrc version=0.11.0>
#<Gem::Specification name=nori version=2.6.0>
#<Gem::Specification name=psych version=2.0.17>
#<Gem::Specification name=rb-fsevent version=0.9.8>
#<Gem::Specification name=rb-inotify version=0.9.8>
#<Gem::Specification name=rb-kqueue version=0.2.4>
#<Gem::Specification name=rdoc version=4.2.1>
#<Gem::Specification name=rest-client version=2.0.2>
#<Gem::Specification name=ruby_dep version=1.3.1>
#<Gem::Specification name=rubyntlm version=0.6.2>
#<Gem::Specification name=rubyzip version=1.2.1>
#<Gem::Specification name=unf version=0.1.4>
#<Gem::Specification name=unf_ext version=0.0.7.4>
#<Gem::Specification name=vagrant version=1.9.5>
#<Gem::Specification name=vagrant-share version=1.1.8>
#<Gem::Specification name=wdm version=0.1.1>
#<Gem::Specification name=winrm version=2.2.3>
#<Gem::Specification name=winrm-elevated version=1.1.0>
#<Gem::Specification name=winrm-fs version=1.0.1>

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
Copy link
Author

gbonk commented May 23, 2017

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
Copy link
Author

gbonk commented May 23, 2017

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
Copy link
Author

gbonk commented May 23, 2017

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
Copy link

xi-ao commented Jun 13, 2017

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.

spajus added a commit to spajus/vagrant-berkshelf-nochefdk that referenced this issue Nov 9, 2017
Motivation: not everyone who are trying to run Vagrant with Chef
provisioning prefer to have the bulky installation of ChefDK, and
berksfile gem simply works.

Judging by the amount of issues complaining about being unable to locate
berksfile gem, this is often a problem:
berkshelf#318
berkshelf#315
@pbc
Copy link

pbc commented Nov 22, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants