- From: Bryan McLellan <
>
- To:
- Subject: [chef] Re: Re: howto install a ruby gem that's a pre-req of a chef recipe
- Date: Fri, 17 Aug 2012 11:11:42 -0400
On Thu, Aug 16, 2012 at 1:12 PM, Joshua Blatt
<
>
wrote:
>
After playing with this a bit, I found that chef loads libraries before the
>
recipe is compiled so sometimes you can't use that gem_package resource in
>
time.
libraries are evaluated before recipes in the compilation phase [1].
What you need to do is a) use chef_gem and b) move your requires in
your libraries where they aren't evaluated until the recipe is
converged.
# library_gem/libraries/check_mysql.rb
module CheckMysql
def check
require 'mysql'
# do something
end
end
# EOF
# library_gem/recipes/default.rb
class Chef::Recipe
include CheckMysql
end
chef_gem "mysql"
check
# EOF
>
I also noticed that the opscode database cookbook has this problem too.
>
The 'added:' lines below addressed the problem for me, but is this a
>
colossal hack? Would love to know if I'm doing something stupid here or
>
depending on internals that may change in the futureā¦.
That is an unnecessary hack.
The mysql gem should (must) be installed with chef_gem (or the old
gem_package.run_action hack) in a recipe before the mysql library is
required in a chef cookbook library.
The simplest course of action for this part of the discussion is to
look at the database cookbook refactor that was recently completed
[1].
Bryan
[1]
http://lists.opscode.com/sympa/arc/chef/2012-08/msg00206.html
Archive powered by MHonArc 2.6.16.