2016-11-04 65 views
0

我有一个厨师12.5风格的自定义资源,需要安装gem才能在load_current_value块中“要求”它。我尝试使用chef_gem资源,但当我在那里使用时,我在chef_gem上得到了一个N​​oMethodError。这工作:厨师12.5式自定义资源:安装load_current_value块所需的gem?

load_current_value do 
    Chef::Resource::ChefGem.new 'inifile' do 
    compile_time true 
    end 
    require 'inifile' 
    # ... load_current_value code 
end 

...但显式调用Chef::Resource::ChefGem.new似乎是错误的,或者至少是 “不雅”。

这使宝石可用于行动,这很方便。但是我想知道是否有更合适的方法在load_current_value块中(或之前)安装chef_gem?

回答

2

如果我没有记错的厨师12.8它可能specify gems in metadata.rb(找宝石关键字):

Specifies a gem dependency to be installed via the chef_gem resource after 
all cookbooks are synchronized, but before any other cookbook loading is 
done. Use this attribute once per gem dependency. 

我觉得这是“东西”,你正在寻找。

+0

是的,谢谢。这是正确的答案。这在一般情况下工作,并解决我的''load_current_value''问题。 因为使用''gem'mysql2'''这样崩溃了(希望是一个暂时的问题,由于缺少包依赖),所以我放弃了 - 忘记了 - 使用元数据解决方案。 –

+0

问题在于,当厨师启动时,在编译器或mysql库可用之前(假设您通过配方安装这些库),它会安装gem。这可能导致订购困难。 – coderanger

+0

..它需要你的cheffed主机都可以访问rubygems.org或者临时gem下载代理。 安全问题很有趣。 – user2066657