Chef 属性在数组哈希中设置一个变量

Chef Attribute set a variable in an array hash

在食谱中,我的 attributes/default.rb:

default.ark.packages = [ 
  {
    'name' => 'optipng',
    'url' => 'http://squirrelyjim.cloudfront.net/heroes/optipng-0.7.5.tar.gz', 
    'version' => '0.7.5'
  },
  {
    'name' => 'imagemagick',
    'url' => 'http://squirrelyjim.cloudfront.net/heroes/ImageMagick-6.9.0-4.tar.gz',
    'version' => '6.9.0-4'
  },
  {
    'name' => 'jpegoptim',
    'url' => 'http://squirrelyjim.cloudfront.net/heroes/jpegoptim-1.4.1.tar.gz',
    'version' => '1.4.1'
  }
]

然后我使用方舟资源调用这些值如下:

node.ark.packages.each do |pkg|  
  ark pkg['name'] do
    url pkg['url']
    version pkg['version']
    action :install_with_make
    notifies :run, "execute[ldconfig]", :immediately
  end
end

这很好用,但我想以某种方式让版本在 url 结束时自动调用,而不是输入两次。有没有一种方法可以用同一哈希中的另一个值更新哈希中的值,类似于:

http://squirrelyjim.cloudfront.net/heroes/optipng-#{version}.tar.gz

在循环内动态构建 URL:

node.ark.packages.each do |pkg|  
  url = "http://squirrelyjim.cloudfront.net/heroes/#{pkg['name']}-#{pkg['version']}.tar.gz"

  ark pkg['name'] do
    url url
    version pkg['version']
    action :install_with_make
    notifies :run, "execute[ldconfig]", :immediately
  end
end