I'm developing a cookbook to deploy a simple ROR application. I write an app_helper.rb and put it into the libraries directory of my cookbook, here is the content:
module AppHelper
def self.find_gem
if File.exists?("/usr/local/rvm/bin/rvm")
return `/usr/local/rvm/bin/rvm default exec which gem`.chomp
else
return "/usr/bin/gem"
end
end
end
In the recipes/default.rb, I mix in the above module into Chef::Recipe class
class Chef::Recipe
include AppHelper
end
As you know, the find_gem function can be called from anywhere of the recipe.
when I'm trying to use the find_gem function in my ruby_block like this:
ruby_block "find gem" do
block do
gem_bin = Chef::Recipe::find_gem
# or gem_bin = find_gem
end
end
I got a NoMethodError: undefined method 'find_gem'.
Also try to mix in the module into Chef::Resource::RubyBlock, it doesn't work neither.
class Chef::Resource::RubyBlock
include AppHelper
end
ruby_block "find gem" do
block do
gem_bin = Chef::Resource::RubyBlock::find_gem
# or gem_bin = find_gem
end
end
Is there any way to call the function in the module from the ruby_block? Or Is there an variable of chef to location the files in the libraries, so that I can be able to require the module in the ruby_block.
Thanks!
Chef::Resource
and not intoChef::Recipe
as your code actually says. – GrillworkChef::Resource::RubyBlock.find_gem
– Grillwork