繁体   English   中英

在Chef LWRP中安装,要求和使用ruby库

[英]Installing, requiring, and using a ruby library in chef lwrp

我正在编写LWRP,以使用API​​密钥播种Redis数据库以进行身份​​验证。 我的麻烦是将redis库用于ruby。 我到处搜索并在网上找到了一些示例,但对我没有任何帮助。

我正在AWS OpsWorks上运行此程序,因此它正在使用Chef-solo

我尝试在运行列表中包括安装Redis gem的食谱( 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'

我是红宝石新手,所以感谢您的所有帮助。

因此,似乎我丢失了一小块,而我在错误的地方放了几样东西。

首先,在我的食谱中安装了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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM