gpt4 book ai didi

ruby - 在 chef lwrp 中安装、要求和使用 ruby​​ 库

转载 作者:可可西里 更新时间:2023-11-01 11:43:35 25 4
gpt4 key购买 nike

我正在编写一个 LWRP 以使用 API key 为 redis 数据库播种以允许进行身份验证。我的麻烦是使用 ruby​​ 的 redis 库。我四处搜索并在网上找到了一些示例,但没有一个对我有用。

我在 AWS OpsWorks 上运行它,所以它使用的是 chef-solo

我已经尝试在我的运行列表中包含一个安装 redis gem ( https://github.com/brianbianco/redisio/blob/master/recipes/redis_gem.rb ) 的方法

我也试过在 Recipe 中安装它们 gem。

    r = gem_package "redis" do
action :install
end

r.run_action(:install)

    r = chef_gem "redis" do
action :install
end

r.run_action(:install)

这是我在 Chef 运行中遇到的错误

[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'

我是 ruby​​ 的新手,所以非常感谢您的帮助,谢谢。

最佳答案

看来我遗漏了一小块,而且我在错误的地方放置了一些东西。

首先我需要在我的 Recipe 中安装 redis gem 后刷新 gem,如下所示。

r = chef_gem "redis" do
action :nothing
end

r.run_action(:install)
Gem.clear_paths

我还要求我的提供程序中的库不正确。我需要在 Gem.clear_paths 之后在我的 Recipe 中要求它,然后在我的提供者中我将打开连接并预制添加、删除或更新记录,如下所示。

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

关于ruby - 在 chef lwrp 中安装、要求和使用 ruby​​ 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19164144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com