I have been trying to learn chef recently because I was planning on using it for deploying server config and server application software. I am having issues understanding h
The java cookbook is designed to support the installation of different Java variants. It's behaviour is controlled by node attributes. The defaults are in the cookbook and will install the OpenJDK.
So, to install the oracle JDK you need to specify alternative overrides and these are discussed in the README
How do you do this? In chef you have at least two options:
For an example of a wrapper cookbook I refer you to my other answer.
For an example role try this:
{
"name": "java",
"description": "Oracle java role",
"override_attributes": {
"java": {
"jdk_version": 8,
"install_flavor": "oracle",
"oracle": {
"accept_oracle_download_terms": true
}
}
},
"run_list": [
"recipe[apt]",
"recipe[java]"
]
}
Add this role to the run-list of your node and the OracleJDK will be installed.
The following is a test kitchen example that will install and test a "java" role against both ubuntu and centos
├── Berksfile
├── .kitchen.yml
├── roles
│ └── java.json
└── test
└── integration
└── default
└── serverspec
└── java_spec.rb
Install chefDK, vagrant and run the following command
kitchen test
Notes:
source "https://supermarket.chef.io"
cookbook "apt"
cookbook "java"
---
driver:
name: vagrant
provisioner:
name: chef_zero
require_chef_omnibus: 12.0.3
client_rb:
"Ohai::Config[:disabled_plugins] = [:GCE] #":
platforms:
- name: ubuntu-12.04
- name: centos-6.4
suites:
- name: default
run_list:
- role[java]
Notes:
See above
require 'serverspec'
# Required by serverspec
set :backend, :exec
describe file('/usr/lib/jvm/java-8-oracle-amd64/release'), :if => os[:family] == "ubuntu" do
it { should contain 'JAVA_VERSION="1.8.0_31"' }
end
describe file('/usr/lib/jvm/java/release'), :if => os[:family] == "redhat" do
it { should contain 'JAVA_VERSION="1.8.0_31"' }
end