2013-10-03 49 views
0

我正在編寫一個LWRP,用API密鑰對redis數據庫進行種子處理以允許進行身份驗證。我的麻煩是使用redis庫進行ruby。我搜索了一下,發現了一些在線的例子,沒有任何工作可以幫助我。在廚師中安裝,需要和使用ruby庫lwrp

我在AWS OpsWorks運行此所以它是用廚師獨奏

我試過,包括我跑列表中的食譜,安裝Redis的寶石(https://github.com/brianbianco/redisio/blob/master/recipes/redis_gem.rb

我也試過在烹飪書中安裝寶石。

r = gem_package "redis" do 
     action :install 
    end 

    r.run_action(:install) 

r = chef_gem "redis" do 
     action :install 
    end 

    r.run_action(:install) 

這是我正在讓我的廚師跑

[2013-10-03T16:11:41+00:00] DEBUG: filtered backtrace of compile error: 
[2013-10-03T16:11:41+00:00] DEBUG: filtered backtrace of compile error: 
[2013-10-03T16:11:41+00:00] DEBUG: backtrace entry for compile error: '/opt/aws/opsworks/releases/20130926123105_208/site-cookbooks/ilnkmx/providers/add_app.rb:1:in `require'' 
[2013-10-03T16:11:41+00:00] DEBUG: Line number of compile error: '1' 
[2013-10-03T16:11:42+00:00] ERROR: Caught exception while compiling OpsWorks custom run list: LoadError - no such file to load -- redis - /opt/aws/opsworks/releases/20130926123105_208/site-cookbooks/ilnkmx/providers/add_app.rb:1:in `require' 

我是新來的紅寶石所以任何錯誤和所有幫助讚賞,謝謝。

回答

0

所以看起來我錯過了一小塊,我在錯誤的地方有幾件事。

首先我需要在我的配方中安裝redis gem後刷新寶石,看起來像這樣。

r = chef_gem "redis" do 
    action :nothing 
end 

r.run_action(:install) 
Gem.clear_paths 

我還要求我的提供程序中的庫不正確。我需要在Gem.clear_paths之後在我的配方中要求它,然後在我的提供商中,我將打開連接並預製新增,刪除或更新看起來像這樣的記錄。

action :create do 
    if @current_resource.exists 
     Chef::Log.info "#{ @new_resource } already exist - nothing to do." 
    else 
     converge_by("Create #{ @new_resource }") do 
      create_app_key 
     end 
    end 
end 

def create_app_key 
    redis = ::Redis.new 
    redis.set "#{@new_resource.app_name}", "#{@new_resource.api_key}" 
end