0

如何在循环中编写此内容。我对 ruby​​ 很陌生,所以在这种方法上很挣扎。

我正在尝试创建响应文件,然后更新 IHS(IBM HTTP Server)的修订包

    #Install the fix pack for IHS

template "/tmp/ihs-fixpack-response1.txt" do
  source "ihs-fixpack-response.erb"
  mode 0755
  owner "root"
  group "root"
  variables({
    :fixpack => "7.0.0-WS-IHS-LinuxX32-FP0000019.pak",
    :product_path => node[:websphere][:ihs][:ihs_path]
  })
end

# code for installing Fixpack
bash "ihs/was-updateinstaller" do
  user "root"
  code %(#{node[:websphere][:ihs][:ihs_updi_path]}/update.sh  -options "/tmp/ihs-fixpack-response1.txt" -silent)

end

#Install the fix pack for the plugin.
template "/tmp/ihs-fixpack-response2.txt" do
  source "ihs-fixpack-response.erb"
  mode 0755
  owner "root"
  group "root"
  variables({
    :fixpack => "7.0.0-WS-PLG-LinuxX32-FP0000019.pak",
    :product_path => node[:websphere][:ihs][:ihs_wasPluginPath]
  })
end

# code for installing Fixpack
bash "ihs/was-updateinstaller" do
  user "root"
  code %(#{node[:websphere][:ihs][:ihs_updi_path]}/update.sh  -options "/tmp/ihs-fixpack-response2.txt" -silent)
end
4

1 回答 1

3

我相信这会做你想要的:

[ [ "7.0.0-WS-IHS-LinuxX32-FP0000019.pak", node[:websphere][:ihs][:ihs_path] ],
  [ "7.0.0-WS-PLG-LinuxX32-FP0000019.pak", node[:websphere][:ihs][:ihs_wasPluginPath] ]
].zip(1..2).each do |vars, i|
  template "/tmp/ihs-fixpack-response#{i}.txt" do
    source "ihs-fixpack-response.erb"
    mode 0755
    owner "root"
    group "root"
    variables({
      :fixpack => vars.first,
      :product_path => vars.last
    })
  end

  bash "ihs/was-updateinstaller" do
    user "root"
    code %(#{node[:websphere][:ihs][:ihs_updi_path]}/update.sh  -options "/tmp/ihs-fixpack-response#{i}.txt" -silent)
  end
end
于 2013-06-06T00:22:48.427 回答