相关疑难解决方法(0)

如何在厨师ruby_block中要求我的库

我正在开发一本食谱来部署一个简单的ROR应用程序.我写了一个app_helper.rb并把它放到我的cookbook的libraries目录中,这里是内容:

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
Run Code Online (Sandbox Code Playgroud)

在recipes/default.rb中,我将上面的模块混合到Chef :: Recipe类中

class Chef::Recipe
  include AppHelper
end
Run Code Online (Sandbox Code Playgroud)

如您所知,可以从配方的任何位置调用find_gem函数.

当我试图在我的ruby_block中使用find_gem函数时,如下所示:

ruby_block "find gem" do
   block do
    gem_bin = Chef::Recipe::find_gem
    # or gem_bin = find_gem
  end
end
Run Code Online (Sandbox Code Playgroud)

我得到了一个N​​oMethodError:未定义的方法'find_gem'.

还尝试将模块混合到Chef :: Resource :: RubyBlock中,它既不起作用也不起作用.

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
Run Code Online (Sandbox Code Playgroud)

有没有办法从ruby_block调用模块中的函数?或者是否有一个厨师变量来定位库中的文件,以便我能够在ruby_block中需要该模块.

谢谢!

cookbook chef-infra

15
推荐指数
1
解决办法
2万
查看次数

标签 统计

chef-infra ×1

cookbook ×1