在 OpsWorks Chef 配方中安装 S3 中的 gem



我需要net-ssh和net-scp作为自定义OpsWorks厨师食谱的一部分。

由于未能提供宝石而偶尔 rubygems.org 失败,因此我想自己在 S3 上托管它们。

chef_gem有"source"参数,但它似乎要求在 chef 启动之前存在本地文件(所以我不能在使用 remote_file chef_gem之前立即下载该文件)

$gemSsh = "#{Chef::Config[:file_cache_path]}/net-ssh.gem"
$gemScp = "#{Chef::Config[:file_cache_path]}/net-scp.gem"
remote_file $gemSsh do
    source "https://s3-us-west-2.amazonaws.com/****/net-ssh-2.9.1.gem"
    action :nothing
end.run_action(:create)
remote_file $gemScp do
    source "https://s3-us-west-2.amazonaws.com/****/net-scp-1.2.1.gem"
    action :nothing
end.run_action(:create)
chef_gem "net-ssh" do
    action :nothing
    source $gemSsh
end.run_action(:install)
chef_gem "net-scp" do
    action :nothing
    source $gemScp
end.run_action(:install)

(注意:run_action(:install) 基于此处的评论 https://tickets.opscode.com/browse/CHEF-4843)

此操作失败并显示以下错误:

NoMethodError
-------------
undefined method `name' for "/var/lib/aws/opsworks/cache.stage2/net-scp.gem":String

Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/opsworks_commons/libraries/monkey_patch_rubygems_provider.rb:55:in `install'
/var/lib/aws/opsworks/cache.stage2/cookbooks/****/recipes/default.rb:24:in `from_file'

您可以使用 gem install 提供的 "--local" 标志(您可以使用 gem install --help 找到其他选项)。

基本命令会像gem install --local path_to_gem/filename.gem一样。因此,在这种情况下,您的食谱将是:

....
chef_gem "net-ssh" do
    action :nothing
    options("--local #{$gemSsh}")
end.run_action(:install)
chef_gem "net-scp" do
    action :nothing
    options("--local #{$gemScp}")
end.run_action(:install)

最新更新