[chef] Re: Re: Using Chef to install Java (my first recipe)


Chronological Thread 
  • From: Jasna Benčić < >
  • To:
  • Subject: [chef] Re: Re: Using Chef to install Java (my first recipe)
  • Date: Fri, 14 Mar 2014 00:45:56 +0100

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 < " target="_blank"> > 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 < " target="_blank"> > 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:


 :~/dev/chef/jenkins$ knife solo cook 
 
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.0
Running 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 ip6address
Compiling 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 handlers
Running 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.out
Chef 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!






Archive powered by MHonArc 2.6.16.

§