# Using Chef to install Java (my first recipe)

**URL:** <https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111>\
**Category:** Chef Infra (archive)\
**Created:** [March 13, 2014, 11:15pm UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111 "2014-03-13T23:15:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discourse.chef.io/u/phil_swenson)\
**Post date:** [March 13, 2014, 11:15pm UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/1 "2014-03-13T23:15:53Z")

</div>

I'm a Chef newbie and am struggling with writing a recipe to install Java  
(and eventually install Jenkins nodes and configure jobs).

my recipes/default.rb looks like:

package "git-core"  
include\_recipe "java::oracle"

directory '/jenkins' do  
user 'jenkins'  
group 'root'  
mode '0700'  
end

my nodes/hostname.json file looks like:

{  
"java": {  
"jdk\_version": "7",  
"java\_home": "opt/java",  
"oracle" : {  
"accept\_oracle\_download\_terms": true  
}  
},  
"run\_list":["recipe[main]"]}

Here is my execution output:

philswenson@zoso:~/dev/chef/jenkins$ knife solo cook root@redstone  
WARNING: solo.rb found, but since knife-solo v0.3.0 it is not used any more  
WARNING: Please read the upgrade instructions:  
[https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0Running](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0Running)  
Chef on redstone...Checking Chef version...Uploading the  
kitchen...Generating solo config...Running Chef...Starting Chef  
Client, version 11.10.4[2014-03-13T16:15:27-04:00] WARN: unable to  
detect ip6addressCompiling Cookbooks...[2014-03-13T16:15:27-04:00]  
WARN: Using java::default instead is recommended.  
================================================================================Recipe  
Compile Error in  
/root/chef-solo/cookbooks-2/main/recipes/default.rb================================================================================

NoMethodError-------------  
undefined method `' for nil:NilClass

Cookbook Trace:---------------  
/root/chef-solo/cookbooks-2/java/recipes/oracle.rb:38:in `from_file' /root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'

Relevant File Content:----------------------/root/chef-solo/cookbooks-2/java/recipes/oracle.rb:

31:  
32: case node['java']['jdk\_version'].to\_s  
33: when "6"  
34: tarball\_url = node['java']['jdk']['6'][arch]['url']  
35: tarball\_checksum = node['java']['jdk']['6'][arch]['checksum']  
36: bin\_cmds = node['java']['jdk']['6']['bin\_cmds']  
37: when "7"  
38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']  
39: tarball\_checksum = node['java']['jdk']['7'][arch]['checksum']  
40: bin\_cmds = node['java']['jdk']['7']['bin\_cmds']  
41: end  
42:  
43: if tarball\_url =~ /example.com/  
44: Chef::Application.fatal!("You must change the download link to  
your private repository. You can no longer download java directly from  
[http://download.oracle.com](http://download.oracle.com) without a web broswer")  
45: end  
46:  
47: include\_recipe "java::set\_java\_home"

Running handlers:[2014-03-13T16:15:27-04:00] ERROR: Running exception  
handlersRunning handlers complete  
[2014-03-13T16:15:27-04:00] ERROR: Exception handlers  
complete[2014-03-13T16:15:27-04:00] FATAL: Stacktrace dumped to  
/var/chef/cache/chef-stacktrace.outChef Client failed. 0 resources  
updated in 0.258671344 seconds[2014-03-13T16:15:27-04:00] ERROR:  
undefined method `' for nil:NilClass[2014-03-13T16:15:27-04:00]  
FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited  
unsuccessfully (exit code 1)  
ERROR: RuntimeError: chef-solo failed. See output above.

Here are my questions:

1. I'm guessing that I shouldn't have to put these recipe settings in my  
nodes/hostname.json file. I tried putting them in the recipe (they will  
need to apply to all nodes), but couldn't get that to work.

2. I'm sure my java config is wrong, but I'm not sure how. the error is  
undefined method of nil onnode['java']['jdk']['7'][arch]['url']

The default.rb attributes for the java recipe has this in it, so I don't  
know why I would get the nil:

default['java']['jdk']['7']['x86\_64']['url'] =  
'[http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz](http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz)'

thanks for any thoughts!

---

<div class="post-metadata">

**Author:** ![carmstrong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/carmstrong/32/346_2.png) [@carmstrong](https://discourse.chef.io/u/carmstrong)\
**Post date:** [March 13, 2014, 11:37pm UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/2 "2014-03-13T23:37:50Z")

</div>

Change include\_recipe "java::oracle" to be include\_recipe "java::default"

Then, set on the node: node['java']['install\_flavor'] = 'oracle'

On Thu, Mar 13, 2014 at 4:15 PM, phil swenson [phil.swenson@gmail.com](mailto:phil.swenson@gmail.com)wrote:

> I'm a Chef newbie and am struggling with writing a recipe to install Java  
> (and eventually install Jenkins nodes and configure jobs).
> 
> my recipes/default.rb looks like:
> 
> package "git-core"  
> include\_recipe "java::oracle"
> 
> directory '/jenkins' do  
> user 'jenkins'  
> group 'root'  
> mode '0700'  
> end
> 
> my nodes/hostname.json file looks like:
> 
> {  
> "java": {  
> "jdk\_version": "7",  
> "java\_home": "opt/java",  
> "oracle" : {  
> "accept\_oracle\_download\_terms": true  
> }  
> },  
> "run\_list":["recipe[main]"]}
> 
> Here is my execution output:
> 
> philswenson@zoso:~/dev/chef/jenkins$ knife solo cook root@redstone  
> WARNING: solo.rb found, but since knife-solo v0.3.0 it is not used any more  
> WARNING: Please read the upgrade instructions: [Create new page · matschaffer/knife-solo Wiki · GitHub](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0Running) Chef on redstone...Checking Chef version...Uploading the kitchen...Generating solo config...Running Chef...Starting Chef Client, version 11.10.4[2014-03-13T16:15:27-04:00] WARN: unable to detect ip6addressCompiling Cookbooks...[2014-03-13T16:15:27-04:00] WARN: Using java::default instead is recommended.  
> ================================================================================Recipe Compile Error in /root/chef-solo/cookbooks-2/main/recipes/default.rb================================================================================
> 
> NoMethodError-------------  
> undefined method `' for nil:NilClass
> 
> Cookbook Trace:---------------  
> /root/chef-solo/cookbooks-2/java/recipes/oracle.rb:38:in `from_file' /root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'
> 
> Relevant File Content:----------------------/root/chef-solo/cookbooks-2/java/recipes/oracle.rb:
> 
> 31:  
> 32: case node['java']['jdk\_version'].to\_s  
> 33: when "6"  
> 34: tarball\_url = node['java']['jdk']['6'][arch]['url']  
> 35: tarball\_checksum = node['java']['jdk']['6'][arch]['checksum']  
> 36: bin\_cmds = node['java']['jdk']['6']['bin\_cmds']  
> 37: when "7"  
> 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']  
> 39: tarball\_checksum = node['java']['jdk']['7'][arch]['checksum']  
> 40: bin\_cmds = node['java']['jdk']['7']['bin\_cmds']  
> 41: end  
> 42:  
> 43: if tarball\_url =~ /example.com/  
> 44: Chef::Application.fatal!("You must change the download link to your private repository. You can no longer download java directly from [http://download.oracle.com](http://download.oracle.com) without a web broswer")  
> 45: end  
> 46:  
> 47: include\_recipe "java::set\_java\_home"
> 
> Running handlers:[2014-03-13T16:15:27-04:00] ERROR: Running exception handlersRunning handlers complete  
> [2014-03-13T16:15:27-04:00] ERROR: Exception handlers complete[2014-03-13T16:15:27-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.outChef Client failed. 0 resources updated in 0.258671344 seconds[2014-03-13T16:15:27-04:00] ERROR: undefined method `' for nil:NilClass[2014-03-13T16:15:27-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)  
> ERROR: RuntimeError: chef-solo failed. See output above.
> 
> Here are my questions:
> 
> 1. I'm guessing that I shouldn't have to put these recipe settings in my  
> nodes/hostname.json file. I tried putting them in the recipe (they will  
> need to apply to all nodes), but couldn't get that to work.
> 
> 2. I'm sure my java config is wrong, but I'm not sure how. the error is  
> undefined method of nil onnode['java']['jdk']['7'][arch]['url']
> 
> The default.rb attributes for the java recipe has this in it, so I don't  
> know why I would get the nil:
> 
> default['java']['jdk']['7']['x86\_64']['url'] = '[Unauthorized Request](http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz)'
> 
> thanks for any thoughts!

---

<div class="post-metadata">

**Author:** ![Jasna\_Bencic](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Jasna\_Bencic](https://discourse.chef.io/u/Jasna_Bencic)\
**Post date:** [March 13, 2014, 11:45pm UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/3 "2014-03-13T23:45:56Z")

</div>

troubleshoot tip

always look for Chef's pointer like on line 38 because Chef usually points  
out to you where is the problem, also check line 11 in your default.rb

38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']

your default recipe could look different - package has to be installed so  
something is missing in that code, then you only gave right to some  
directory, without creating it first

On Fri, Mar 14, 2014 at 12:37 AM, Christopher Armstrong \<  
[chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me)\> wrote:

> Change include\_recipe "java::oracle" to be include\_recipe "java::default"
> 
> Then, set on the node: node['java']['install\_flavor'] = 'oracle'
> 
> On Thu, Mar 13, 2014 at 4:15 PM, phil swenson [phil.swenson@gmail.com](mailto:phil.swenson@gmail.com)wrote:
> 
> > I'm a Chef newbie and am struggling with writing a recipe to install Java  
> > (and eventually install Jenkins nodes and configure jobs).
> > 
> > my recipes/default.rb looks like:
> > 
> > package "git-core"  
> > include\_recipe "java::oracle"
> > 
> > directory '/jenkins' do  
> > user 'jenkins'  
> > group 'root'  
> > mode '0700'  
> > end
> > 
> > my nodes/hostname.json file looks like:
> > 
> > {  
> > "java": {  
> > "jdk\_version": "7",  
> > "java\_home": "opt/java",  
> > "oracle" : {  
> > "accept\_oracle\_download\_terms": true  
> > }  
> > },  
> > "run\_list":["recipe[main]"]}
> > 
> > Here is my execution output:
> > 
> > philswenson@zoso:~/dev/chef/jenkins$ knife solo cook root@redstone  
> > WARNING: solo.rb found, but since knife-solo v0.3.0 it is not used any more  
> > WARNING: Please read the upgrade instructions: [Create new page · matschaffer/knife-solo Wiki · GitHub](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0Running) Chef on redstone...Checking Chef version...Uploading the kitchen...Generating solo config...Running Chef...Starting Chef Client, version 11.10.4[2014-03-13T16:15:27-04:00] WARN: unable to detect ip6addressCompiling Cookbooks...[2014-03-13T16:15:27-04:00] WARN: Using java::default instead is recommended.  
> > ================================================================================Recipe Compile Error in /root/chef-solo/cookbooks-2/main/recipes/default.rb================================================================================
> > 
> > NoMethodError-------------  
> > undefined method `' for nil:NilClass
> > 
> > Cookbook Trace:---------------  
> > /root/chef-solo/cookbooks-2/java/recipes/oracle.rb:38:in `from_file' /root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'
> > 
> > Relevant File Content:----------------------/root/chef-solo/cookbooks-2/java/recipes/oracle.rb:
> > 
> > 31:  
> > 32: case node['java']['jdk\_version'].to\_s  
> > 33: when "6"  
> > 34: tarball\_url = node['java']['jdk']['6'][arch]['url']  
> > 35: tarball\_checksum = node['java']['jdk']['6'][arch]['checksum']  
> > 36: bin\_cmds = node['java']['jdk']['6']['bin\_cmds']  
> > 37: when "7"  
> > 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']  
> > 39: tarball\_checksum = node['java']['jdk']['7'][arch]['checksum']  
> > 40: bin\_cmds = node['java']['jdk']['7']['bin\_cmds']  
> > 41: end  
> > 42:  
> > 43: if tarball\_url =~ /example.com/  
> > 44: Chef::Application.fatal!("You must change the download link to your private repository. You can no longer download java directly from [http://download.oracle.com](http://download.oracle.com) without a web broswer")  
> > 45: end  
> > 46:  
> > 47: include\_recipe "java::set\_java\_home"
> > 
> > Running handlers:[2014-03-13T16:15:27-04:00] ERROR: Running exception handlersRunning handlers complete  
> > [2014-03-13T16:15:27-04:00] ERROR: Exception handlers complete[2014-03-13T16:15:27-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.outChef Client failed. 0 resources updated in 0.258671344 seconds[2014-03-13T16:15:27-04:00] ERROR: undefined method `' for nil:NilClass[2014-03-13T16:15:27-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)  
> > ERROR: RuntimeError: chef-solo failed. See output above.
> > 
> > Here are my questions:
> > 
> > 1. I'm guessing that I shouldn't have to put these recipe settings in my  
> > nodes/hostname.json file. I tried putting them in the recipe (they will  
> > need to apply to all nodes), but couldn't get that to work.
> > 
> > 2. I'm sure my java config is wrong, but I'm not sure how. the error is  
> > undefined method of nil onnode['java']['jdk']['7'][arch]['url']
> > 
> > The default.rb attributes for the java recipe has this in it, so I don't  
> > know why I would get the nil:
> > 
> > default['java']['jdk']['7']['x86\_64']['url'] = '[Unauthorized Request](http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz)'
> > 
> > thanks for any thoughts!

---

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discourse.chef.io/u/phil_swenson)\
**Post date:** [March 14, 2014, 2:06am UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/4 "2014-03-14T02:06:36Z")

</div>

On Thu, Mar 13, 2014 at 5:37 PM, Christopher Armstrong \<  
[chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me)\> wrote:

> node['java']['install\_flavor'] = 'oracle'

Which file do I set "node['java']['install\_flavor'_] = 'oracle'"??_

_this is something fundamental to chef I don't get. I tried setting this in  
main/recipes/default.rb but node evaluates to nil._

_thanks_  
_phil_

_error:_

## NoMethodError

undefined method `' for nil:NilClass

## Cookbook Trace:

/root/chef-solo/cookbooks-2/java/recipes/set\_attributes\_from\_version.rb:22:in  
`from_file' /root/chef-solo/cookbooks-2/java/recipes/default.rb:21:in `from\_file'  
/root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'

## Relevant File Content:

/root/chef-solo/cookbooks-2/java/recipes/set\_attributes\_from\_version.rb:

15:  
16: # Calculate variables that depend on jdk\_version  
17: # If you need to override this in an attribute file you must use  
18: # force\_default or higher precedence.  
19:  
20: case node['platform\_family']  
21: when "rhel", "fedora"  
22\>\> case node['java']['install\_flavor']  
23: when "oracle"  
24: node.default['java']['java\_home'] = "/usr/lib/jvm/java"  
25: when "oracle\_rpm"  
26: node.default['java']['java\_home'] = "/usr/java/latest"  
27: else  
28: node.default['java']['java\_home'] =  
"/usr/lib/jvm/java-1.#{node['java']['jdk\_version']}.0"  
29: end  
30: node.default['java']['openjdk\_packages'] =  
["java-1.#{node['java']['jdk\_version']}.0-openjdk",  
"java-1.#{node['java']['jdk\_version']}.0-openjdk-devel"]  
31: when "freebsd"

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [March 14, 2014, 2:14am UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/5 "2014-03-14T02:14:53Z")

</div>

Usually, reasonable defaults will have been set for you (in 3rd party cookbooks) in an attributes file, usually attributes/default.rb

Note that on chef-solo, you can cause yourself problems if you do the following:

1. add a cookbook to your cookbook\_path
2. run a recipe from that cookbook with `include_recipe` without specifying the dependency in the including recipe’s metadata.rb

What happens in that case is, chef will directly include the recipe without having first loaded that cookbook’s supporting files (like the attributes files). This happens because chef uses the dependency information to determine the correct order to load cookbook’s non-recipe files, and a cookbook that isn’t reachable from the run\_list or dependencies isn’t loaded at all.

So, assuming this is your issue, you can fix it by adding the java cookbook as a dependency of whatever cookbook you’re including it from.

--  
Daniel DeLeo

On Thursday, March 13, 2014 at 7:06 PM, phil swenson wrote:

> On Thu, Mar 13, 2014 at 5:37 PM, Christopher Armstrong \<[chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me) ([mailto:chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me))\> wrote:
> 
> > node['java']['install\_flavor'] = 'oracle'
> 
> Which file do I set “node['java']['install\_flavor'] = ‘oracle’”??
> 
> this is something fundamental to chef I don’t get. I tried setting this in main/recipes/default.rb but node evaluates to nil.
> 
> thanks  
> phil
> 
> error:
> 
> ## NoMethodError
> 
> undefined method `' for nil:NilClass
> 
> ## Cookbook Trace:
> 
> /root/chef-solo/cookbooks-2/java/recipes/set\_attributes\_from\_version.rb:22:in `from_file' /root/chef-solo/cookbooks-2/java/recipes/default.rb:21:in `from\_file'  
> /root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'
> 
> ## Relevant File Content:
> 
> /root/chef-solo/cookbooks-2/java/recipes/set\_attributes\_from\_version.rb:
> 
> 15:  
> 16: # Calculate variables that depend on jdk\_version  
> 17: # If you need to override this in an attribute file you must use  
> 18: # force\_default or higher precedence.  
> 19:  
> 20: case node['platform\_family']  
> 21: when "rhel", "fedora"  
> 22\>\> case node['java']['install\_flavor']  
> 23: when "oracle"  
> 24: node.default['java']['java\_home'] = "/usr/lib/jvm/java"  
> 25: when "oracle\_rpm"  
> 26: node.default['java']['java\_home'] = "/usr/java/latest"  
> 27: else  
> 28: node.default['java']['java\_home'] = "/usr/lib/jvm/java-1.#{node['java']['jdk\_version']}.0"  
> 29: end  
> 30: node.default['java']['openjdk\_packages'] = ["java-1.#{node['java']['jdk\_version']}.0-openjdk", "java-1.#{node['java']['jdk\_version']}.0-openjdk-devel"]  
> 31: when "freebsd"

---

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discourse.chef.io/u/phil_swenson)\
**Post date:** [March 14, 2014, 2:20am UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/6 "2014-03-14T02:20:58Z")

</div>

right but this setting has a default in the java recipe, so why doesn’t  
that get picked up?

On Thu, Mar 13, 2014 at 5:45 PM, Jasna Benčić [jasna.bencic@teamsnap.com](mailto:jasna.bencic@teamsnap.com)wrote:

> troubleshoot tip
> 
> always look for Chef's pointer like on line 38 because Chef usually points  
> out to you where is the problem, also check line 11 in your default.rb
> 
> 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']
> 
> your default recipe could look different - package has to be installed so  
> something is missing in that code, then you only gave right to some  
> directory, without creating it first
> 
> On Fri, Mar 14, 2014 at 12:37 AM, Christopher Armstrong \<  
> [chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me)\> wrote:
> 
> > Change include\_recipe "java::oracle" to be include\_recipe "java::default"
> > 
> > Then, set on the node: node['java']['install\_flavor'] = 'oracle'
> > 
> > On Thu, Mar 13, 2014 at 4:15 PM, phil swenson [phil.swenson@gmail.com](mailto:phil.swenson@gmail.com)wrote:
> > 
> > > I'm a Chef newbie and am struggling with writing a recipe to install  
> > > Java (and eventually install Jenkins nodes and configure jobs).
> > > 
> > > my recipes/default.rb looks like:
> > > 
> > > package "git-core"  
> > > include\_recipe "java::oracle"
> > > 
> > > directory '/jenkins' do  
> > > user 'jenkins'  
> > > group 'root'  
> > > mode '0700'  
> > > end
> > > 
> > > my nodes/hostname.json file looks like:
> > > 
> > > {  
> > > "java": {  
> > > "jdk\_version": "7",  
> > > "java\_home": "opt/java",  
> > > "oracle" : {  
> > > "accept\_oracle\_download\_terms": true  
> > > }  
> > > },  
> > > "run\_list":["recipe[main]"]}
> > > 
> > > Here is my execution output:
> > > 
> > > philswenson@zoso:~/dev/chef/jenkins$ knife solo cook root@redstone  
> > > WARNING: solo.rb found, but since knife-solo v0.3.0 it is not used any more  
> > > WARNING: Please read the upgrade instructions: [Create new page · matschaffer/knife-solo Wiki · GitHub](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0Running) Chef on redstone...Checking Chef version...Uploading the kitchen...Generating solo config...Running Chef...Starting Chef Client, version 11.10.4[2014-03-13T16:15:27-04:00] WARN: unable to detect ip6addressCompiling Cookbooks...[2014-03-13T16:15:27-04:00] WARN: Using java::default instead is recommended.  
> > > ================================================================================Recipe Compile Error in /root/chef-solo/cookbooks-2/main/recipes/default.rb================================================================================
> > > 
> > > NoMethodError-------------  
> > > undefined method `' for nil:NilClass
> > > 
> > > Cookbook Trace:---------------  
> > > /root/chef-solo/cookbooks-2/java/recipes/oracle.rb:38:in `from_file' /root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'
> > > 
> > > Relevant File Content:----------------------/root/chef-solo/cookbooks-2/java/recipes/oracle.rb:
> > > 
> > > 31:  
> > > 32: case node['java']['jdk\_version'].to\_s  
> > > 33: when "6"  
> > > 34: tarball\_url = node['java']['jdk']['6'][arch]['url']  
> > > 35: tarball\_checksum = node['java']['jdk']['6'][arch]['checksum']  
> > > 36: bin\_cmds = node['java']['jdk']['6']['bin\_cmds']  
> > > 37: when "7"  
> > > 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']  
> > > 39: tarball\_checksum = node['java']['jdk']['7'][arch]['checksum']  
> > > 40: bin\_cmds = node['java']['jdk']['7']['bin\_cmds']  
> > > 41: end  
> > > 42:  
> > > 43: if tarball\_url =~ /example.com/  
> > > 44: Chef::Application.fatal!("You must change the download link to your private repository. You can no longer download java directly from [http://download.oracle.com](http://download.oracle.com) without a web broswer")  
> > > 45: end  
> > > 46:  
> > > 47: include\_recipe "java::set\_java\_home"
> > > 
> > > Running handlers:[2014-03-13T16:15:27-04:00] ERROR: Running exception handlersRunning handlers complete  
> > > [2014-03-13T16:15:27-04:00] ERROR: Exception handlers complete[2014-03-13T16:15:27-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.outChef Client failed. 0 resources updated in 0.258671344 seconds[2014-03-13T16:15:27-04:00] ERROR: undefined method `' for nil:NilClass[2014-03-13T16:15:27-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)  
> > > ERROR: RuntimeError: chef-solo failed. See output above.
> > > 
> > > Here are my questions:
> > > 
> > > 1. I'm guessing that I shouldn't have to put these recipe settings in my  
> > > nodes/hostname.json file. I tried putting them in the recipe (they will  
> > > need to apply to all nodes), but couldn't get that to work.
> > > 
> > > 2. I'm sure my java config is wrong, but I'm not sure how. the error is  
> > > undefined method of nil onnode['java']['jdk']['7'][arch]['url']
> > > 
> > > The default.rb attributes for the java recipe has this in it, so I don't  
> > > know why I would get the nil:
> > > 
> > > default['java']['jdk']['7']['x86\_64']['url'] = '[Unauthorized Request](http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz)'
> > > 
> > > thanks for any thoughts!

---

<div class="post-metadata">

**Author:** ![carmstrong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/carmstrong/32/346_2.png) [@carmstrong](https://discourse.chef.io/u/carmstrong)\
**Post date:** [March 14, 2014, 2:30am UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/7 "2014-03-14T02:30:17Z")

</div>

Because you're including the oracle recipe directly, not using the default  
recipe. There are required attributes set in the  
set\_attributes\_from\_version recipe, which is included by the default  
recipe. You can include this yourself before including java::oracle, but  
the recommended method is just to include default (which is why you're  
getting that warning when the recipe executes).

I'm the maintainer of the java cookbook, and we pulled out some logic from  
the default recipe into set\_attributes\_from\_version so that the cookbook  
could more easily be wrapped. For most uses, simply including the default  
recipe and setting the install\_flavor node attribute (if you wish to  
override the default) is sufficient. Perhaps we can make this clearer (such  
as raising an exception when expected attributes aren't set).

Anyhow, in this case, changing your include\_recipe to include default  
instead of oracle and then in your node attributes (nodes/hostname.json in  
your case), just set install\_flavor = 'oracle'.

On Thu, Mar 13, 2014 at 7:20 PM, phil swenson [phil.swenson@gmail.com](mailto:phil.swenson@gmail.com)wrote:

> right but this setting has a default in the java recipe, so why doesn’t  
> that get picked up?
> 
> On Thu, Mar 13, 2014 at 5:45 PM, Jasna Benčić [jasna.bencic@teamsnap.com](mailto:jasna.bencic@teamsnap.com)wrote:
> 
> > troubleshoot tip
> > 
> > always look for Chef's pointer like on line 38 because Chef usually  
> > points out to you where is the problem, also check line 11 in your  
> > default.rb
> > 
> > 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']
> > 
> > your default recipe could look different - package has to be installed so  
> > something is missing in that code, then you only gave right to some  
> > directory, without creating it first
> > 
> > On Fri, Mar 14, 2014 at 12:37 AM, Christopher Armstrong \<  
> > [chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me)\> wrote:
> > 
> > > Change include\_recipe "java::oracle" to be include\_recipe  
> > > "java::default"
> > > 
> > > Then, set on the node: node['java']['install\_flavor'] = 'oracle'
> > > 
> > > On Thu, Mar 13, 2014 at 4:15 PM, phil swenson [phil.swenson@gmail.com](mailto:phil.swenson@gmail.com)wrote:
> > > 
> > > > I'm a Chef newbie and am struggling with writing a recipe to install  
> > > > Java (and eventually install Jenkins nodes and configure jobs).
> > > > 
> > > > my recipes/default.rb looks like:
> > > > 
> > > > package "git-core"  
> > > > include\_recipe "java::oracle"
> > > > 
> > > > directory '/jenkins' do  
> > > > user 'jenkins'  
> > > > group 'root'  
> > > > mode '0700'  
> > > > end
> > > > 
> > > > my nodes/hostname.json file looks like:
> > > > 
> > > > {  
> > > > "java": {  
> > > > "jdk\_version": "7",  
> > > > "java\_home": "opt/java",  
> > > > "oracle" : {  
> > > > "accept\_oracle\_download\_terms": true  
> > > > }  
> > > > },  
> > > > "run\_list":["recipe[main]"]}
> > > > 
> > > > Here is my execution output:
> > > > 
> > > > philswenson@zoso:~/dev/chef/jenkins$ knife solo cook root@redstone  
> > > > WARNING: solo.rb found, but since knife-solo v0.3.0 it is not used any more  
> > > > WARNING: Please read the upgrade instructions: [Create new page · matschaffer/knife-solo Wiki · GitHub](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0Running) Chef on redstone...Checking Chef version...Uploading the kitchen...Generating solo config...Running Chef...Starting Chef Client, version 11.10.4[2014-03-13T16:15:27-04:00] WARN: unable to detect ip6addressCompiling Cookbooks...[2014-03-13T16:15:27-04:00] WARN: Using java::default instead is recommended.  
> > > > ================================================================================Recipe Compile Error in /root/chef-solo/cookbooks-2/main/recipes/default.rb================================================================================
> > > > 
> > > > NoMethodError-------------  
> > > > undefined method `' for nil:NilClass
> > > > 
> > > > Cookbook Trace:---------------  
> > > > /root/chef-solo/cookbooks-2/java/recipes/oracle.rb:38:in `from_file' /root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'
> > > > 
> > > > Relevant File Content:----------------------/root/chef-solo/cookbooks-2/java/recipes/oracle.rb:
> > > > 
> > > > 31:  
> > > > 32: case node['java']['jdk\_version'].to\_s  
> > > > 33: when "6"  
> > > > 34: tarball\_url = node['java']['jdk']['6'][arch]['url']  
> > > > 35: tarball\_checksum = node['java']['jdk']['6'][arch]['checksum']  
> > > > 36: bin\_cmds = node['java']['jdk']['6']['bin\_cmds']  
> > > > 37: when "7"  
> > > > 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']  
> > > > 39: tarball\_checksum = node['java']['jdk']['7'][arch]['checksum']  
> > > > 40: bin\_cmds = node['java']['jdk']['7']['bin\_cmds']  
> > > > 41: end  
> > > > 42:  
> > > > 43: if tarball\_url =~ /example.com/  
> > > > 44: Chef::Application.fatal!("You must change the download link to your private repository. You can no longer download java directly from [http://download.oracle.com](http://download.oracle.com) without a web broswer")  
> > > > 45: end  
> > > > 46:  
> > > > 47: include\_recipe "java::set\_java\_home"
> > > > 
> > > > Running handlers:[2014-03-13T16:15:27-04:00] ERROR: Running exception handlersRunning handlers complete  
> > > > [2014-03-13T16:15:27-04:00] ERROR: Exception handlers complete[2014-03-13T16:15:27-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.outChef Client failed. 0 resources updated in 0.258671344 seconds[2014-03-13T16:15:27-04:00] ERROR: undefined method `' for nil:NilClass[2014-03-13T16:15:27-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)  
> > > > ERROR: RuntimeError: chef-solo failed. See output above.
> > > > 
> > > > Here are my questions:
> > > > 
> > > > 1. I'm guessing that I shouldn't have to put these recipe settings in  
> > > > my nodes/hostname.json file. I tried putting them in the recipe (they will  
> > > > need to apply to all nodes), but couldn't get that to work.
> > > > 
> > > > 2. I'm sure my java config is wrong, but I'm not sure how. the error is  
> > > > undefined method of nil onnode['java']['jdk']['7'][arch]['url']
> > > > 
> > > > The default.rb attributes for the java recipe has this in it, so I  
> > > > don't know why I would get the nil:
> > > > 
> > > > default['java']['jdk']['7']['x86\_64']['url'] = '[Unauthorized Request](http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz)'
> > > > 
> > > > thanks for any thoughts!

---

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discourse.chef.io/u/phil_swenson)\
**Post date:** [March 14, 2014, 4:16pm UTC](https://discourse.chef.io/t/using-chef-to-install-java-my-first-recipe/5111/8 "2014-03-14T16:16:22Z")

</div>

Thanks Christopher,

I do think it would be great to put in validation for missing attributes.

I made the change you suggested, this is in my default.rb:

include\_recipe "java::default"

and this is my redstone.json:  
{  
"java": {  
"jdk\_version": "7",  
"java\_home": "opt/java",  
"oracle" : {  
"accept\_oracle\_download\_terms": true  
},  
"install\_flavor": "oracle"  
},

```
"run_list":["recipe[main]"]

```

}

I now get this error:

## NoMethodError

undefined method `' for nil:NilClass

…

38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']  
39: tarball\_checksum = node['java']['jdk']['7'][arch]['checksum']  
40: bin\_cmds = node['java']['jdk']['7']['bin\_cmds']  
41: end

So do I need to push the JDK tar file a URL somewhere and point at that?

If I look at the java recipe code I see this in attributes/default.rb:

# x86\_64

default['java']['jdk']['7']['x86\_64']['url'] = '

> **[Unauthorized Request](https://download.oracle.com/errors/download-fail-1505220.html)**

'

I’m confused why this setting isn’t picked up?

Also, if I want to configure these settings in my default.rb instead of the  
node.jsonvia ruby code, like:

node['java']['install\_flavor'] = ‘oracle'

node gets evaluated to nil…. i see examples like this everywhere though.

thanks for any help!

phil

On Thu, Mar 13, 2014 at 8:30 PM, Christopher Armstrong \<  
[chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me)\> wrote:

> Because you're including the oracle recipe directly, not using the default  
> recipe. There are required attributes set in the  
> set\_attributes\_from\_version recipe, which is included by the default  
> recipe. You can include this yourself before including java::oracle, but  
> the recommended method is just to include default (which is why you're  
> getting that warning when the recipe executes).
> 
> I'm the maintainer of the java cookbook, and we pulled out some logic from  
> the default recipe into set\_attributes\_from\_version so that the cookbook  
> could more easily be wrapped. For most uses, simply including the default  
> recipe and setting the install\_flavor node attribute (if you wish to  
> override the default) is sufficient. Perhaps we can make this clearer (such  
> as raising an exception when expected attributes aren't set).
> 
> Anyhow, in this case, changing your include\_recipe to include default  
> instead of oracle and then in your node attributes (nodes/hostname.json in  
> your case), just set install\_flavor = 'oracle'.
> 
> On Thu, Mar 13, 2014 at 7:20 PM, phil swenson [phil.swenson@gmail.com](mailto:phil.swenson@gmail.com)wrote:
> 
> > right but this setting has a default in the java recipe, so why doesn’t  
> > that get picked up?
> > 
> > On Thu, Mar 13, 2014 at 5:45 PM, Jasna Benčić [jasna.bencic@teamsnap.com](mailto:jasna.bencic@teamsnap.com)wrote:
> > 
> > > troubleshoot tip
> > > 
> > > always look for Chef's pointer like on line 38 because Chef usually  
> > > points out to you where is the problem, also check line 11 in your  
> > > default.rb
> > > 
> > > 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']
> > > 
> > > your default recipe could look different - package has to be installed  
> > > so something is missing in that code, then you only gave right to some  
> > > directory, without creating it first
> > > 
> > > On Fri, Mar 14, 2014 at 12:37 AM, Christopher Armstrong \<  
> > > [chris@chrisarmstrong.me](mailto:chris@chrisarmstrong.me)\> wrote:
> > > 
> > > > Change include\_recipe "java::oracle" to be include\_recipe  
> > > > "java::default"
> > > > 
> > > > Then, set on the node: node['java']['install\_flavor'] = 'oracle'
> > > > 
> > > > On Thu, Mar 13, 2014 at 4:15 PM, phil swenson [phil.swenson@gmail.com](mailto:phil.swenson@gmail.com)wrote:
> > > > 
> > > > > I'm a Chef newbie and am struggling with writing a recipe to install  
> > > > > Java (and eventually install Jenkins nodes and configure jobs).
> > > > > 
> > > > > my recipes/default.rb looks like:
> > > > > 
> > > > > package "git-core"  
> > > > > include\_recipe "java::oracle"
> > > > > 
> > > > > directory '/jenkins' do  
> > > > > user 'jenkins'  
> > > > > group 'root'  
> > > > > mode '0700'  
> > > > > end
> > > > > 
> > > > > my nodes/hostname.json file looks like:
> > > > > 
> > > > > {  
> > > > > "java": {  
> > > > > "jdk\_version": "7",  
> > > > > "java\_home": "opt/java",  
> > > > > "oracle" : {  
> > > > > "accept\_oracle\_download\_terms": true  
> > > > > }  
> > > > > },  
> > > > > "run\_list":["recipe[main]"]}
> > > > > 
> > > > > Here is my execution output:
> > > > > 
> > > > > philswenson@zoso:~/dev/chef/jenkins$ knife solo cook root@redstone  
> > > > > WARNING: solo.rb found, but since knife-solo v0.3.0 it is not used any more  
> > > > > WARNING: Please read the upgrade instructions: [Create new page · matschaffer/knife-solo Wiki · GitHub](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0Running) Chef on redstone...Checking Chef version...Uploading the kitchen...Generating solo config...Running Chef...Starting Chef Client, version 11.10.4[2014-03-13T16:15:27-04:00] WARN: unable to detect ip6addressCompiling Cookbooks...[2014-03-13T16:15:27-04:00] WARN: Using java::default instead is recommended.  
> > > > > ================================================================================Recipe Compile Error in /root/chef-solo/cookbooks-2/main/recipes/default.rb================================================================================
> > > > > 
> > > > > NoMethodError-------------  
> > > > > undefined method `' for nil:NilClass
> > > > > 
> > > > > Cookbook Trace:---------------  
> > > > > /root/chef-solo/cookbooks-2/java/recipes/oracle.rb:38:in `from_file' /root/chef-solo/cookbooks-2/main/recipes/default.rb:11:in `from\_file'
> > > > > 
> > > > > Relevant File Content:----------------------/root/chef-solo/cookbooks-2/java/recipes/oracle.rb:
> > > > > 
> > > > > 31:  
> > > > > 32: case node['java']['jdk\_version'].to\_s  
> > > > > 33: when "6"  
> > > > > 34: tarball\_url = node['java']['jdk']['6'][arch]['url']  
> > > > > 35: tarball\_checksum = node['java']['jdk']['6'][arch]['checksum']  
> > > > > 36: bin\_cmds = node['java']['jdk']['6']['bin\_cmds']  
> > > > > 37: when "7"  
> > > > > 38\>\> tarball\_url = node['java']['jdk']['7'][arch]['url']  
> > > > > 39: tarball\_checksum = node['java']['jdk']['7'][arch]['checksum']  
> > > > > 40: bin\_cmds = node['java']['jdk']['7']['bin\_cmds']  
> > > > > 41: end  
> > > > > 42:  
> > > > > 43: if tarball\_url =~ /example.com/  
> > > > > 44: Chef::Application.fatal!("You must change the download link to your private repository. You can no longer download java directly from [http://download.oracle.com](http://download.oracle.com) without a web broswer")  
> > > > > 45: end  
> > > > > 46:  
> > > > > 47: include\_recipe "java::set\_java\_home"
> > > > > 
> > > > > Running handlers:[2014-03-13T16:15:27-04:00] ERROR: Running exception handlersRunning handlers complete  
> > > > > [2014-03-13T16:15:27-04:00] ERROR: Exception handlers complete[2014-03-13T16:15:27-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.outChef Client failed. 0 resources updated in 0.258671344 seconds[2014-03-13T16:15:27-04:00] ERROR: undefined method `' for nil:NilClass[2014-03-13T16:15:27-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)  
> > > > > ERROR: RuntimeError: chef-solo failed. See output above.
> > > > > 
> > > > > Here are my questions:
> > > > > 
> > > > > 1. I'm guessing that I shouldn't have to put these recipe settings in  
> > > > > my nodes/hostname.json file. I tried putting them in the recipe (they will  
> > > > > need to apply to all nodes), but couldn't get that to work.
> > > > > 
> > > > > 2. I'm sure my java config is wrong, but I'm not sure how. the error  
> > > > > is undefined method of nil onnode['java']['jdk']['7'][arch]['url']
> > > > > 
> > > > > The default.rb attributes for the java recipe has this in it, so I  
> > > > > don't know why I would get the nil:
> > > > > 
> > > > > default['java']['jdk']['7']['x86\_64']['url'] = '[Unauthorized Request](http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz)'
> > > > > 
> > > > > thanks for any thoughts!
