basho-labs/riak-chef-cookbook

RuntimeError with Vagrant/Chef-solo

Closed this issue · 5 comments

I am getting a runtime error when trying to install Riak onto a Vagrant VirtualBox VM using Chef-solo and Berkshelf.

The Vagrantfile is:

Vagrant.configure("2") do |config|
  config.berkshelf.enabled = true
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

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

The Berksfile is:

cookbook "riak"

Host OS: Mac OS X 10.8.3
Guest OS: Ubuntu 12.04
Vagrant: 1.2.2
Chef: 10.14.2

I may be missing something obvious, but am kind of new to Chef.

The chef output when running vagrant up is:

[2013-05-23T19:33:23+00:00] INFO: *** Chef 10.14.2 ***
[2013-05-23T19:33:24+00:00] INFO: Setting the run_list to ["recipe[riak]"] from JSON
[2013-05-23T19:33:24+00:00] INFO: Run List is [recipe[riak]]
[2013-05-23T19:33:24+00:00] INFO: Run List expands to [riak]
[2013-05-23T19:33:24+00:00] INFO: Starting Chef Run for precise64
[2013-05-23T19:33:24+00:00] INFO: Running start handlers
[2013-05-23T19:33:24+00:00] INFO: Start handlers complete.
[2013-05-23T19:33:24+00:00] INFO: Processing template[/etc/pam.d/su] action create (ulimit::default line 12)
[2013-05-23T19:33:24+00:00] INFO: template[/etc/pam.d/su] backed up to /var/chef/backup/etc/pam.d/su.chef-20130523193324
[2013-05-23T19:33:24+00:00] INFO: template[/etc/pam.d/su] updated content
[2013-05-23T19:33:24+00:00] INFO: Processing execute[apt-get-update] action run (apt::default line 22)
[2013-05-23T19:33:34+00:00] INFO: execute[apt-get-update] ran successfully
[2013-05-23T19:33:34+00:00] INFO: Processing execute[apt-get update] action nothing (apt::default line 29)
[2013-05-23T19:33:34+00:00] INFO: Processing execute[apt-get autoremove] action nothing (apt::default line 36)
[2013-05-23T19:33:34+00:00] INFO: Processing execute[apt-get autoclean] action nothing (apt::default line 42)
[2013-05-23T19:33:34+00:00] INFO: Processing package[update-notifier-common] action install (apt::default line 48)
[2013-05-23T19:33:37+00:00] INFO: package[update-notifier-common] sending run action to execute[apt-get-update] (immediate)
[2013-05-23T19:33:37+00:00] INFO: Processing execute[apt-get-update] action run (apt::default line 22)
[2013-05-23T19:33:40+00:00] INFO: execute[apt-get-update] ran successfully
[2013-05-23T19:33:40+00:00] INFO: Processing execute[apt-get-update-periodic] action run (apt::default line 52)
[2013-05-23T19:33:40+00:00] INFO: Processing directory[/var/cache/local] action create (apt::default line 62)
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local] created directory /var/cache/local
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local] owner changed to 0
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local] group changed to 0
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local] mode changed to 755
[2013-05-23T19:33:40+00:00] INFO: Processing directory[/var/cache/local/preseeding] action create (apt::default line 62)
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local/preseeding] created directory /var/cache/local/preseeding
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local/preseeding] owner changed to 0
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local/preseeding] group changed to 0
[2013-05-23T19:33:40+00:00] INFO: directory[/var/cache/local/preseeding] mode changed to 755
[2013-05-23T19:33:40+00:00] INFO: Processing apt_repository[basho] action add (riak::default line 50)

================================================================================
Error executing action `add` on resource 'apt_repository[basho]'
================================================================================

RuntimeError
------------
The repository file to create is nil, cannot continue.

Cookbook Trace:
---------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/apt/providers/repository.rb:127:in `class_from_file'

Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/riak/recipes/default.rb

 49:     
 50:     apt_repository "basho" do
 51:       uri "http://apt.basho.com"
 52:       distribution node['lsb']['codename']
 53:       components ["main"]
 54:       key "http://apt.basho.com/gpg/basho.apt.key"
 55:     end
 56: 

Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/riak/recipes/default.rb:50:in `from_file'

apt_repository("basho") do
  uri "http://apt.basho.com"
  retry_delay 2
  distribution "precise"
  retries 0
  recipe_name "default"
  action :add
  cookbook_name :riak
  key "http://apt.basho.com/gpg/basho.apt.key"
  components ["main"]
end

[2013-05-23T19:33:40+00:00] ERROR: Running exception handlers
[2013-05-23T19:33:40+00:00] ERROR: Exception handlers complete
[2013-05-23T19:33:40+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-05-23T19:33:40+00:00] FATAL: RuntimeError: apt_repository[basho] (riak::default line 50) had an error: RuntimeError: The repository file to create is nil, cannot continue.
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Hey @jgoodall,

It looks like Riak's dependent cookbooks aren't being pulled down. The apt_repository resource is part of the apt cookbook.

You may need to install the following Vagrant plugin for Berkself [0]. It automatically uses Berkshelf to resolve dependencies before Vagrant runs.

Another recommendation would be to use the following Vagrant box, produced by Opscode, for a more recent version of Chef [1].

[0] https://github.com/riotgames/vagrant-berkshelf
[1] https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.4.4.box

The vagrant-berkshelf plugin is installed:

$ vagrant plugin list
vagrant-berkshelf (1.2.0)

Berkshelf seems to be doing its thing correctly - I clipped the output, but here is the output:

Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise64'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[Berkshelf] Updating Vagrant's berkshelf: '/Users/ojg/.berkshelf/vagrant/berkshelf-20130523-1448-1n897ij'
[Berkshelf] Using riak (2.0.1)
[Berkshelf] Using apt (1.9.2)
[Berkshelf] Using yum (2.2.2)
[Berkshelf] Using build-essential (1.4.0)
[Berkshelf] Using erlang (1.3.0)
[Berkshelf] Using git (2.5.0)
[Berkshelf] Using dmg (1.1.0)
[Berkshelf] Using windows (1.8.10)
[Berkshelf] Using chef_handler (1.1.4)
[Berkshelf] Using runit (1.1.4)
[Berkshelf] Using ulimit (0.2.0)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[default] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...

...

I will try a different disk image.

After a bit more work trying to reproduce this issue, it looks like version 1.8.2+ of apt cookbook requires Chef 10.16.4 or greater. Because we haven't pinned a specific version of the apt cookbook, it's pulling the most current version (1.9.2 in this case).

If you only upgrade Chef, you'll see an error message similar to this:

2013-05-23T22:21:01+00:00] INFO: *** Chef 11.4.4 ***
[2013-05-23T22:21:01+00:00] INFO: Setting the run_list to ["recipe[riak]"] from JSON
[2013-05-23T22:21:01+00:00] INFO: Run List is [recipe[riak]]
[2013-05-23T22:21:01+00:00] INFO: Run List expands to [riak]
[2013-05-23T22:21:01+00:00] INFO: Starting Chef Run for precise64
[2013-05-23T22:21:01+00:00] INFO: Running start handlers
[2013-05-23T22:21:01+00:00] INFO: Start handlers complete.

================================================================================
Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/apt/resources/preference.rb
================================================================================



ArgumentError
-------------
wrong number of arguments (2 for 1)


Cookbook Trace:
---------------
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/resource/lwrp_base.rb:42:in `const_defined?'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/resource/lwrp_base.rb:42:in `build_from_file'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:208:in `load_lwrp_resource'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:193:in `load_lwrps_from_cookbook'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:192:in `each'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:192:in `load_lwrps_from_cookbook'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:120:in `compile_lwrps'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:119:in `each'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:119:in `compile_lwrps'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context/cookbook_compiler.rb:72:in `compile'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/run_context.rb:86:in `load'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/client.rb:224:in `setup_run_context'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/client.rb:467:in `do_run'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/client.rb:200:in `run'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/application.rb:190:in `run_chef_client'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/application/solo.rb:239:in `run_application'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/application/solo.rb:231:in `loop'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/application/solo.rb:231:in `run_application'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/application.rb:73:in `run'
  /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/chef-solo:25
  /opt/vagrant_ruby/bin/chef-solo:19:in `load'
  /opt/vagrant_ruby/bin/chef-solo:19


Relevant File Content:
----------------------
/opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-11.4.4/bin/../lib/chef/resource/lwrp_base.rb:

 35:
 36:        # Evaluates the LWRP resource file and instantiates a new Resource class.
 37:        def self.build_from_file(cookbook_name, filename, run_context)
 38:          rname = filename_to_qualified_string(cookbook_name, filename)
 39:
 40:          # Add log entry if we override an existing light-weight resource.
 41:          class_name = convert_to_class_name(rname)
 42>>         if Resource.const_defined?(class_name, false)
 43:            old_class = Resource.send(:remove_const, class_name)
 44:            # CHEF-3432 -- Chef::Resource keeps a list of subclasses; need to
 45:            # remove old ones from the list when replacing.
 46:            resource_classes.delete(old_class)
 47:            Chef::Log.info("#{class_name} light-weight resource already initialized -- overriding!")
 48:          end
 49:
 50:          resource_class = Class.new(self)
 51:



[2013-05-23T22:21:01+00:00] ERROR: Running exception handlers
[2013-05-23T22:21:01+00:00] ERROR: Exception handlers complete
[2013-05-23T22:21:01+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-05-23T22:21:01+00:00] FATAL: ArgumentError: wrong number of arguments (2 for 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

This appears to be caused by the older version of Ruby installed on the box (1.8.7).

If you want to continue using this Vagrant box, I used the following commands to get a current version of Ruby and Chef installed via Omnibus:

$ sudo apt-get install curl
$ curl -L https://www.opscode.com/chef/install.sh | sudo bash

After that, everything should work.

Thank you! Using a different box (from ubuntu) and installing chef fixed the problem. Below is the Vagrantfile I ended up using that works.

Vagrant.configure("2") do |config|
  config.berkshelf.enabled = true
  config.vm.box = "precise-server-cloudimg-amd64-vagrant-disk1"
  config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/20130523/precise-server-cloudimg-amd64-vagrant-disk1.box"

  # Install latest Chef
  config.vm.provision :shell, :inline => "curl -L https://www.opscode.com/chef/install.sh | sudo bash"

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

Might be worth noting that the shell provisioner line for installing Chef can be done via this plugin as well [0].

[0] https://github.com/schisamo/vagrant-omnibus