在厨师食谱中为java提供不同的安装路径

时间:2014-06-21 16:12:16

标签: java path chef recipe

我正在尝试使用以下代码安装java,但默认情况下它安装在/ usr / java /目录中。我希望它安装在单独的目录中,例如/ u01 / app。

配方

# Remove old environment then notify new environment to be created
ruby_block "delete_environement" do
  block do
    editBashrc = Chef::Util::FileEdit.new("/home/oracle/.bash_profile")
    editBashrc.search_file_delete_line(/^.*#{node['java']['home']} environment settings.*$/)
    editBashrc.search_file_delete_line(/^.*#Auto-generated by Chef Cookbook sun_java.*$/)
    editBashrc.search_file_delete_line(/^.*export JAVA_HOME=.*$/)
    editBashrc.write_file 
  end
  action :create
end

remote_file "#{Chef::Config[:file_cache_path]}/jdk-7u51-linux-x64.rpm" do
  source "http://#######/java/jdk-7u51-linux-x64.rpm"
  mode "0755"
end

rpm_package "javaRPM" do    
  source :"#{Chef::Config[:file_cache_path]}/jdk-7u51-linux-x64.rpm"
  only_if {::File.exists?("#{Chef::Config[:file_cache_path]}/jdk-7u51-linux-x64.rpm")}
  owner :oracle 
  action :install   
end

# update oracle bash profile ~/.bash_profile

execute "create_environment" do
  user "oracle"
  command "echo -e '#{node['java']['home']} environment settings\n#Auto-generated by Chef Cookbook oracle_java\nexport JAVA_HOME=#{node['java']['home']}' >> ~/.bash_profile"
  command "echo -e '#{node['java']['home']} environment settings\n#Auto-generated by Chef Cookbook oracle_java\nexport PATH=$PATH:#{node['java']['home']}/bin' >> ~/.bash_profile"
  command "source ~/.bash_profile"
end

file "javaRPM-cleanup" do
  path "#{Chef::Config[:file_cache_path]}/jdk-7u51-linux-x64.rpm"
  action :delete
end 

1 个答案:

答案 0 :(得分:0)

此问题是您对execute资源的理解。正如我在this post中解释的那样:

  

请注意,Chef只会使用命令属性的最后一个值。这是因为Chef分两个阶段执行 - 编译和执行。

因此,只会执行该序列中的最后一个命令(source ~/.bash_profile)。