【问题标题】:Install gem from S3 in OpsWorks Chef recipe在 OpsWorks Chef 配方中从 S3 安装 gem
【发布时间】:2015-01-31 06:16:32
【问题描述】:

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

rubygems.org 偶尔会出现故障,无法提供 gem,所以我想自己在 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) 基于cmets 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'

【问题讨论】:

    标签: ruby chef-infra aws-opsworks


    【解决方案1】:

    您可以使用 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)
    

    【讨论】:

      猜你喜欢
      • 2021-10-22
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      • 2016-12-12
      • 2020-02-14
      • 1970-01-01
      • 2020-10-23
      相关资源
      最近更新 更多