Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using chef to install Java 7, can't get it to work

I have a wrapper cookbook with one recipe in it, recipes/default.rb that reads the following:

include_recipe "apt"

node.override[:java][:jdk_version] = '7'

include_recipe "java"

I have the apt and java cookbooks from the community site. I'm running knife bootstrap with only this wrapper recipe.

When I converge the node, it installs Java 6 instead of Java 7. I feel like there's something obvious I'm missing, but I can't figure it out. Shouldn't the node.override make it so the default jdk_version of 6 is overridden?

like image 917
Tom Ligda Avatar asked Nov 05 '13 20:11

Tom Ligda


2 Answers

Qualifying my answer with "I'm not a chef expert"... However, I think the issue is with "nested attributes" in Chef. I don't think you can just go ahead and override just the version, because after peeling over every possible thing that could be wrong with your piddly recipe, I found this:

http://lists.opscode.com/sympa/arc/chef/2012-10/msg00265.html

There's some other attributes that are being set after the default jdk version is set. If you look here:

http://community.opscode.com/cookbooks/java/source

You'll see default['java']['openjdk_packages'] gets set using that default version, and the openjdk recipe, which is likely the "install_flavor" being chosen, ONLY looks at that attribute. It doesn't read in the jdk_version directly. Interestingly, the java::oracle recipe (along with java::oracle_i386 and java::oracle_rpm) read in the version directly, so your initial attempt would have worked for that.

I would try setting the version with one of these, based on your particular platform:

Redhat/CentOS: node.override[:java][:openjdk_packages] = ["java-1.7.0-openjdk", "java-1.7.0-openjdk-devel"]
Debian/Ubuntu: node.override[:java][:openjdk_packages] = ["openjdk-7-jdk"]

Other "platform_family" choices can be found here: https://github.com/opscode-cookbooks/java/blob/master/attributes/default.rb

like image 106
sdanzig Avatar answered Nov 14 '22 14:11

sdanzig


Here is how I got it to work with a wrapper cookbook.

I had to add this statement to the attributes/default.rb:

override[:java][:openjdk_packages] = [
  "openjdk-7-jdk", "openjdk-7-jre-headless"
  ]

I tried adding the jdk_version in this location and it didn't work. I tried adding this statement (with node.override) in the wrapper cookbook recipe and it didn't work either.

Here is a description of why this is the case.

like image 3
Tom Ligda Avatar answered Nov 14 '22 14:11

Tom Ligda