Saurav
Saurav

Reputation: 424

Chef template and using it in a loop

How to write this in a loop. I am very new to ruby so struggling with the approach.

I am trying to create a response file and then update the fixpack for 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

Upvotes: 0

Views: 796

Answers (1)

cassianoleal
cassianoleal

Reputation: 2566

I believe this will do what you want:

[ [ "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

Upvotes: 3

Related Questions