Logo
My Journal
Blog

Timeline

Blog

Oracle Java Chef Recipe

There are a number of Java recipes out there that are quite good but I really had a need for a lightweight one with minimal fuss and for Ubuntu only. I would wrap this up as a solo cookbook but there really isn’t a point since it’s a grand total of 45 lines and requires 1 attribute defined. Check it out and see what you think.

# 
# Cookbook Name:: opsworks 
# Recipe:: jdk-install # 
# Author:: John Lawson 
# Email:: jlawson@scriobha.im # 
# 
log "...::: opsworks::jdk-install :::..." 

# Install JDK repo 
execute "apt-get install -y software-properties-common; add-apt-repository -y ppa:webupd8team/java;" do 
  user "root" 
  action :run 
  not_if { ::File.exists?("/tmp/configured.jdk") } 
end 

# Update apt-get now that we have the JDK repo added 
execute "apt-get update;" do 
  user "root" 
  action :run 
  not_if { ::File.exists?("/tmp/configured.jdk") } 
end 

# Set our debconf settings for oracle license 
execute "echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections; echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections;" do 
  user "root" 
  action :run 
  not_if { ::File.exists?("/tmp/configured.jdk") } 
end 

#- Install JDK version based on the jdk_version attribute from attributes/default.rb 
if ! node['java']['jdk_version'].nil? 
  execute "apt-get install -y oracle-java#{node['java']['jdk_version']}-installer;" do 
    user "root" 
    action :run 
    not_if { ::File.exists?("/tmp/configured.jdk") } 
  end 
else 
  log "!!!! No JDK Version set in attributes !!!!"; 
end 

#- A Guard to ensure we only execute this once file '/tmp/configured.jdk'

Leave A Comment