Using Chef to install Java (my first recipe)

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
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 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'

thanks for any thoughts!

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.comwrote:

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 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 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'

thanks for any thoughts!

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> 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.comwrote:

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 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 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'

thanks for any thoughts!

On Thu, Mar 13, 2014 at 5:37 PM, Christopher Armstrong <
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"

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)> 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"

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.comwrote:

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> 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.comwrote:

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 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 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'

thanks for any thoughts!

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.comwrote:

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.comwrote:

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> 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.comwrote:

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 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 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'

thanks for any thoughts!

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'] = '
http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz
'

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> 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.comwrote:

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.comwrote:

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> 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.comwrote:

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 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 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'

thanks for any thoughts!