Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to deploy a rails application using chef, for the mysql cookbook to create a database, it needs the mysql gem. The mysql gem is installed system-wide by using an Ubuntu package, but this is not usable by chef-client which runs from /opt/chef/embedded.

I have tried adding this:

chef_gem 'mysql' do
    action :nothing
end.run_action(:install)

But this requires the libmysqlclient-dev Ubuntu package to be installed. Therefore I have also added this before the previous:

package 'libmysqlclient-dev' do
    action :nothing
end.run_action(:install)

But this is done before the apt recipe updates the apt repositories, and therefore the install of libmysqlclient-dev fails.

These 'hacks' look ugly and I am unable to find a way to run the apt-get update at the right time.

Could someone please help me to find the right (the most chef-like) way to solve my problem (the actual problem is to create the database using the application cookbook)?

Update

I have been able to fix the problem with this recipe as an ugly hack... I'm still searching for a better solution:

execute "apt-get update" do
  ignore_failure true
  action :nothing
end.run_action(:run)

node.set['build_essential']['compiletime'] = true
include_recipe "build-essential"

%w{build-essential mysql-client libmysqlclient-dev}.each do |p|
  package p do
    action :nothing
  end.run_action(:install)
end

chef_gem 'mysql' do
  action :nothing
end.run_action(:install)
share|improve this question
1  
There are some tickets tracking the topic of installing "database" gems (for mysql and postgresql specifically) on tickets.opscode.com, COOK-1441, COOK-1384, COOK-1009. –  jtimberman Aug 9 '12 at 18:13

2 Answers 2

The mysql::ruby recipe allow to install packages via node["mysql"]["client"]["packages"]:

Therefore include it in your run list:

run_list(
  #...
  "recipe[mysql::ruby]",
  #...
)

and specify your dependencies in the attributes:

# this is needed for debian based systems
node["mysql"]["client"]["packages"] = ["build-essential","mysql-client","libmysqlclient-dev"]
share|improve this answer

There isn't really a link between the Debian package management system and gem so the answer is probably this:

package "libmysqlclient-dev" do
  action :install
end

gem_package "mysql" do
  action :install
end

(The chef_gem resource does install a gem, but it's only for installing gems to use inside a Chef recipe. See all the gory details at the Chef Resources page).

For keeping apt under control, I recommend using the apt Opscode community cookbook and add recipe[apt] to the beginning of the run list for all nodes.

share|improve this answer
    
I am using chef_gem on purpose, as I already wrote the mysql gem has already been installed in the system... It can't be used by chef-client so I need to install it with chef_gem... –  Tader Aug 8 '12 at 10:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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