- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Re: Re: Using Chef to install Java (my first recipe)
- Date: Thu, 13 Mar 2014 19:14:53 -0700
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
>
<
>
>
(mailto:
)>
>
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"
Archive powered by MHonArc 2.6.16.