Chef:gem依赖于提供者

时间:2017-07-04 11:59:38

标签: chef

我们正在为资源创建提供程序。它代表在给定数据库中创建mongo用户。

class LivingMongoCookbook::UserProvider < Chef::Provider::LWRPBase 
  provides :living_mongo_user
  def whyrun_supported?
   true
  end
  def action_create
   db = Mongo::Connection.new(new_resource.host, new_resource.port).db(new_resource.database)
   users = db.getUsers
   db.createUser({ user: new_resource.user, pwd: new_resource.passwd, roles: [ new_resource.roles ]})
   new_resource.updated_by_last_action(true)
 end
end

我们正在使用mongo ruby​​驱动程序以便能够在db上创建用户。然而,我们收到了这样的信息:

================================================================================
  Recipe Compile Error in /tmp/kitchen/cache/cookbooks/living_mongo/libraries/provider_user.rb
   ================================================================================       LoadError
  ---------
  cannot load such file -- mongo       Cookbook Trace:
  ---------------
    /tmp/kitchen/cache/cookbooks/living_mongo/libraries/provider_user.rb:1:in `<top (required)>'       Relevant File Content:
  ----------------------
  /tmp/kitchen/cache/cookbooks/living_mongo/libraries/provider_user.rb:         1>> require 'mongo'
    2:
    3:  # Chef Provider for creating a user and group for Elasticsearch
    4:  class LivingMongoCookbook::UserProvider < Chef::Provider::LWRPBase
    5:
    6:    provides :living_mongo_user
    7:
    8:    def whyrun_supported?
    9:      true
   10:    end

似乎没有mongo驱动程序。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

假设你有一个最近的主厨版本并且gem不需要C编译器,请将gem 'mongo'添加到metadata.rb,Chef会为你安装它。< / p>