1

Edit: Bug in rubygems 2.4.4. (fixed in 2.4.5)

I'm having trouble installing gems with the embedded ruby that comes with Chef Client v12.2.1, using the chef_gem resource:

  Mixlib::ShellOut::ShellCommandFailed
  ------------------------------------
  chef_gem[zabbixapi] (generic_server_win::libzabbix-deps line 6) had an error: Mixlib::ShellOut::ShellCommand Failed: Expected process to exit with [0], but received '1'
  ---- Begin output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
  STDOUT:
  STDERR: ERROR:  While executing gem ... (Errno::EADDRNOTAVAIL)
      The requested address is not valid in its context. - connect(2)
  ---- End output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
  Ran C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" returned 1

Also:

  • Same result when running the command manually on the command-line as an Administrator with the --local option
  • Same error occurs for other gems.
  • The servers that I'm trying to run this on have no internet access
  • I'm unable to reproduce the problem on a newly installed test machine (with internet access)
  • The version of ruby used is 2.0.0: ruby 2.0.0p451 (2014-02-24) [i386-mingw32]

Here is my Chef recipe:

cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
  source 'zabbixapi-2.2.2.gem'
end

chef_gem "zabbixapi" do
  source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end
3
  • The gem command has to have an internet access to download the required dependencies for the gem you try to install (unless you use a local repository). You have to install each pre-required gem or use a local server if you really can't have an internet access.
    – Tensibai
    May 26, 2015 at 10:07
  • The gem in question only depends on the json gem, which is already installed. (listed in "gem list" output)
    – Nils
    May 26, 2015 at 11:49
  • Upvoting for the research effort and the update to the question :)
    – Tensibai
    May 26, 2015 at 16:11

1 Answer 1

0

You're problem is that the chef_gem resource is special in the way it enforce the use of the embedded ruby in chef installation and that it is run before convergence to allow the gem to be required in recipes. documentation about it here

To use a local source deployed with chef you have to ensure the file is present before, if not the gem command will try to download it (and fail with no internet access).

To ensure your local file is present before the chef_gem call you have to ensure the cookbook_file resource is called at compile time with this trick

in your specific case this should do:

cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
  action :nothing
  source 'zabbixapi-2.2.2.gem'
end.run_action(:create)

chef_gem "zabbixapi" do
  source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end

The action nothing in the resource is to avoid having it called twice (once in compile phase and once in converge phase, even if the later won't have any impact, it's better to save time no evaluating it twice) then calling the action :create at end of the definition will trigger the action in the compile phase and the file will be present for the chef_gem call later.

5
  • You sure are right about needing to download the gem during compile time, however it still doesn't solve my gem install problem. It also fails when manually running gem install with the gem file already being there.
    – Nils
    May 26, 2015 at 12:23
  • Try with a verbose output from command line gem install --verbose ... or even --debug to see what it tries to connect to from command line before retrying with chef (and maybe with a -l debug to the chef-client call to have a more detailed output)
    – Tensibai
    May 26, 2015 at 12:26
  • Running gem with --debug is giving some more clues. It looks like a problem with dns resolving: pastebin.com/ggeGNPcQ The system has no dns servers configured. I still cannot reproduce the problem on another host though.
    – Nils
    May 26, 2015 at 12:41
  • Ok, I'm now able to reproduce. Looks like gem pukes all over itself if no DNS server is configured. Even when installing a local gem.
    – Nils
    May 26, 2015 at 12:52
  • Seems win32 registry gem try to resolve the machine hostname (to find some environment variables maybe) and fails as there is no dns configured, I'm unsure on how to resolve this.
    – Tensibai
    May 26, 2015 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.