2017-07-04 53 views
0

我們正在爲資源創建供應商。它代表在給定的數據庫中創建一個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 

我們lokking使用蒙戈Ruby驅動程序,以便能夠在數據庫創建用戶。然而,我們得到這樣的信息:

================================================================================ 
    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

用'compile_time true'添加'chef_gem'mongo'',這樣它就可以在你的提供者運行之前將寶石安裝到廚師(ruby)中(參見[chef_gem](https://docs.chef.io/resource_chef_gem.html )文檔) – Tensibai

+0

何,並且在調用它的類之前,您必須「需要」mongo'' ... – Tensibai

回答

0

假設您擁有最新版本的Chef版本,並且Gem不需要C編譯器,請將gem 'mongo'添加到metadata.rb,廚師將負責爲您安裝它。