Search code examples
rubychef-infrachef-solo

Chef tutorial fails at chef_gem[mysql] install


I'm following the chef tutorial from:

http://gettingstartedwithchef.com/first-steps-with-chef.html

Everything was working flawlessly until the "Attributes" section. After creating the node['phpapp']['database'] entry and running chef-solo, I get the following. Any ideas? I'm unfamiliar with ruby in general so am struggling to debug it myself.

root@chef-solo:~/chef-repo# chef-solo -c solo.rb -j web.json 
Starting Chef Client, version 11.8.2
Compiling Cookbooks...
/root/chef-repo/cookbooks/homebrew/libraries/homebrew_package.rb:26: warning: toplevel constant Homebrew referenced by Chef::Provider::Package::Homebrew
[2015-03-15T19:08:58+00:00] WARN: Cloning resource attributes for directory[/var/cache/local/preseeding] from prior resource (CHEF-3694)
[2015-03-15T19:08:58+00:00] WARN: Previous directory[/var/cache/local/preseeding]: /root/chef-repo/cookbooks/apt/recipes/default.rb:91:in `block in from_file'
[2015-03-15T19:08:58+00:00] WARN: Current  directory[/var/cache/local/preseeding]: /root/chef-repo/cookbooks/mysql/recipes/_server_debian.rb:4:in `from_file'
[2015-03-15T19:08:58+00:00] WARN: Cloning resource attributes for directory[/var/lib/mysql] from prior resource (CHEF-3694)
[2015-03-15T19:08:58+00:00] WARN: Previous directory[/var/lib/mysql]: /root/chef-repo/cookbooks/mysql/recipes/_server_debian.rb:34:in `block in from_file'
[2015-03-15T19:08:58+00:00] WARN: Current  directory[/var/lib/mysql]: /root/chef-repo/cookbooks/mysql/recipes/_server_debian.rb:78:in `from_file'
[2015-03-15T19:08:58+00:00] WARN: apache2::mod_php5 generally is expected to be run under a non-threaded MPM, such as prefork
[2015-03-15T19:08:58+00:00] WARN: See http://php.net/manual/en/faq.installation.php#faq.installation.apache2
[2015-03-15T19:08:58+00:00] WARN: Currently the apache2 cookbook is configured to use the 'event' MPM
[2015-03-15T19:08:58+00:00] WARN: node['build_essential'] has been changed to node['build-essential'] to match the
cookbook name and community standards. I have gracefully converted the attribute
for you, but this warning and conversion will be removed in the next major
release of the build-essential cookbook.

[2015-03-15T19:08:58+00:00] WARN: node['build-essential']['compiletime'] has been deprecated. Please use
node['build-essential']['compile_time'] instead. I have gracefully converted the
attribute for you, but this warning and converstion will be removed in the next
major release of the build-essential cookbook.

Recipe: build-essential::_debian
  * package[autoconf] action install (up to date)
  * package[binutils-doc] action install (up to date)
  * package[bison] action install (up to date)
  * package[build-essential] action install (up to date)
  * package[flex] action install (up to date)
  * package[gettext] action install (up to date)
  * package[ncurses-dev] action install (up to date)
Recipe: mysql::client
  * package[mysql-client] action install (up to date)
  * package[libmysqlclient-dev] action install (up to date)
Recipe: mysql::ruby
  * chef_gem[mysql] action install
================================================================================
Error executing action `install` on resource 'chef_gem[mysql]'
================================================================================


Gem::Installer::ExtensionBuildError
-----------------------------------
ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:5:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out



Cookbook Trace:
---------------
/root/chef-repo/cookbooks/mysql/recipes/ruby.rb:47:in `from_file'
/root/chef-repo/cookbooks/phpapp/recipes/default.rb:16:in `from_file'


Resource Declaration:
---------------------
# In /root/chef-repo/cookbooks/mysql/recipes/ruby.rb

 47: chef_gem 'mysql'



Compiled Resource:
------------------
# Declared in /root/chef-repo/cookbooks/mysql/recipes/ruby.rb:47:in `from_file'

chef_gem("mysql") do
  provider Chef::Provider::Package::Rubygems
  action :install
  retries 0
  retry_delay 2
  package_name "mysql"
  version "2.9.1"
  cookbook_name :mysql
  recipe_name "ruby"
end




================================================================================
Recipe Compile Error in /root/chef-repo/cookbooks/phpapp/recipes/default.rb
================================================================================


Gem::Installer::ExtensionBuildError
-----------------------------------
chef_gem[mysql] (mysql::ruby line 47) had an error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:5:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out



Cookbook Trace:
---------------
  /root/chef-repo/cookbooks/mysql/recipes/ruby.rb:47:in `from_file'
  /root/chef-repo/cookbooks/phpapp/recipes/default.rb:16:in `from_file'


Relevant File Content:
----------------------
/root/chef-repo/cookbooks/mysql/recipes/ruby.rb:

 40:    end
 41:  end
 42:  
 43:  node['mysql']['client']['packages'].each do |name|
 44:    resources("package[#{name}]").run_action(:install)
 45:  end
 46:  
 47>> chef_gem 'mysql'
 48:  


[2015-03-15T19:09:00+00:00] ERROR: Running exception handlers
[2015-03-15T19:09:00+00:00] ERROR: Exception handlers complete
[2015-03-15T19:09:00+00:00] FATAL: Stacktrace dumped to /root/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2015-03-15T19:09:00+00:00] ERROR: chef_gem[mysql] (mysql::ruby line 47) had an error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:5:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out

[2015-03-15T19:09:00+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
root@chef-solo:~/chef-repo# 

Solution

  • Well I ended up "hacking" it a little.

    apt-get install ruby-all-dev
    

    This resolved the ruby gem issue. I then had an error where it was complaining about something to do with mysql2, so:

    gem install mysql2
    

    My chef run now completes. Thanks guys for the help.