I am building a Vagrant configuration (for Nginx, PHP, and Postgres) with Chef Solo, using the databox cookbook to create databases in Postgresql during provisioning. I kept getting the error below, which I traced to databox::postgresql
's eventual call (via database::paostgresql
) call to the postgresql::ruby
recipe. I tried running postgresql::ruby
directly in my run list, and it produces the same error.
Logging into the VM and running sudo /opt/ruby/bin/gem install pg
works, and the rerunning vagrant provision
works too. However, as I understand it, the whole point of the postgresql::ruby
task is that it installs this gem!
Here is the output from a Chef run that runs only this recipe (edited slightly for readability):
Running chef-solo...
[2014-07-23T19:33:52+00:00] INFO: Forking chef instance to converge...
[2014-07-23T19:33:52+00:00] INFO: *** Chef 11.12.8 ***
[2014-07-23T19:33:52+00:00] INFO: Chef-client pid: 1627
[2014-07-23T19:33:53+00:00] INFO: Setting the run_list to ["postgresql::ruby"] from CLI options
[2014-07-23T19:33:53+00:00] INFO: Run List is [recipe[postgresql::ruby]]
[2014-07-23T19:33:53+00:00] INFO: Run List expands to [postgresql::ruby]
[2014-07-23T19:33:53+00:00] INFO: Starting Chef Run for vm
[2014-07-23T19:33:53+00:00] INFO: Running start handlers
[2014-07-23T19:33:53+00:00] INFO: Start handlers complete.
[2014-07-23T19:33:57+00:00] INFO: execute[apt-get update] ran successfully
[2014-07-23T19:34:09+00:00] INFO: package[ncurses-dev] is a virtual package, actually acting on package[libncurses5-dev]
================================================================================
Error executing action `install` on resource 'chef_gem[pg]'
================================================================================
LoadError
---------
cannot load such file -- pg
Cookbook Trace:
---------------
/tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:25:in `from_file'
Resource Declaration:
---------------------
# In /tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb
58: chef_gem "pg"
59: rescue Gem::Installer::ExtensionBuildError => e
Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:58:in `rescue in from_file'
chef_gem("pg") do
provider Chef::Provider::Package::Rubygems
action :install
retries 0
retry_delay 2
guard_interpreter :default
package_name "pg"
version "0.17.1"
cookbook_name :postgresql
recipe_name "ruby"
end
================================================================================
Recipe Compile Error in /tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb
================================================================================
LoadError
---------
chef_gem[pg] (postgresql::ruby line 58) had an error: LoadError: cannot load such file -- pg
Cookbook Trace:
---------------
/tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:25:in `from_file'
Relevant File Content:
----------------------
/tmp/vagrant-chef-3/chef-solo-1/cookbooks/postgresql/recipes/ruby.rb:
18: # limitations under the License.
19: #
20:
21: # Load the pgdgrepo_rpm_info method from libraries/default.rb
22: ::Chef::Recipe.send(:include, Opscode::PostgresqlHelpers)
23:
24: begin
25>> require 'pg'
26: rescue LoadError
27:
28: if platform_family?('ubuntu', 'debian')
29: e = execute 'apt-get update' do
30: action :nothing
31: end
32: e.run_action(:run) unless ::File.exists?('/var/lib/apt/periodic/update-success-stamp')
33: end
34:
[2014-07-23T19:34:29+00:00] ERROR: Running exception handlers
[2014-07-23T19:34:29+00:00] ERROR: Exception handlers complete
[2014-07-23T19:34:29+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-07-23T19:34:29+00:00] ERROR: chef_gem[pg] (postgresql::ruby line 58) had an error: LoadError: cannot load such file -- pg
[2014-07-23T19:34:29+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
I'm not doing anything unusual in this failing run - the VM is a stock Vagrant Ubuntu 14.04 x64 image built with Packer - and the only thing Packer did to the image is installing Chef and the VirtualBox extensions.
Any idea what's going on here? I don't see anyone else complaining about this - am I doing something wrong or is no one else using this recipe?
Chef is version 11.12.8.
A complete MCVE can be found here
I also posted this as an issue on the postgresql cookbook itself, but I figured it might get more exposure here.
It appears that this issue only happens when Chef is installed as a gem, as far as I can tell.
I switched from using the Chef Gem to using Omnibus, and I was able to get it working correctly.