1

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)
Tader
  • 141
  • 1
  • 6
  • 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 09 '12 at 18:13

2 Answers2

5

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"]
Mic92
  • 196
  • 6
0

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.

Tim Potter
  • 1,754
  • 15
  • 15
  • 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 08 '12 at 10:54