[英]Installing, requiring, and using a ruby library in chef lwrp
I'm writing an LWRP to seed a redis database with API keys to allow for authentication. 我正在编写LWRP,以使用API密钥播种Redis数据库以进行身份验证。 My trouble is using the redis library for ruby.
我的麻烦是将redis库用于ruby。 I've searched around and found a few examples online and nothing has worked for me.
我到处搜索并在网上找到了一些示例,但对我没有任何帮助。
I am running this on AWS OpsWorks so it is using chef-solo 我正在AWS OpsWorks上运行此程序,因此它正在使用Chef-solo
I've tried including a recipe in my run list that installs the redis gem ( https://github.com/brianbianco/redisio/blob/master/recipes/redis_gem.rb ) 我尝试在运行列表中包括安装Redis gem的食谱( https://github.com/brianbianco/redisio/blob/master/recipes/redis_gem.rb )
I've also tried installing them gem inside of the cookbook. 我也尝试将它们安装在食谱中。
r = gem_package "redis" do
action :install
end
r.run_action(:install)
or 要么
r = chef_gem "redis" do
action :install
end
r.run_action(:install)
This is the error that I'm am getting on my chef run 这是我在厨师奔跑中遇到的错误
[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'
I'm new to ruby so any and all help is appreciate, thank you. 我是红宝石新手,所以感谢您的所有帮助。
So it seems I was missing a small piece and I had a few things in the wrong place. 因此,似乎我丢失了一小块,而我在错误的地方放了几样东西。
First I needed to refresh the gems after installing the redis gem in my recipe which looks like this. 首先,在我的食谱中安装了redis gem之后,我需要刷新宝石,如下所示。
r = chef_gem "redis" do
action :nothing
end
r.run_action(:install)
Gem.clear_paths
I was also requiring the library in my Provider which was incorrect. 我还要求提供者中的库不正确。 I needed to require it in my recipe after
Gem.clear_paths
then in my provider I would open the connection and preform add, delete, or update records which looks like this. 我需要在
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.