[chef] Re: Re: Ohai attributes in Default attributes


Chronological Thread 
  • From: Tom < >
  • To:
  • Subject: [chef] Re: Re: Ohai attributes in Default attributes
  • Date: Mon, 18 Mar 2013 22:48:23 +0000

Hi,

Thanks for the reply.

Sorry, I didn't put the whole stack trace in as it didn't seem very useful.

This is it, with the stack trace below it.

================================================================================
Recipe Compile Error in /opt/chef-repo/cookbooks/jockey/attributes/default.rb
================================================================================

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

Cookbook Trace:
---------------
  /opt/chef-repo/cookbooks/jockey/attributes/default.rb:30:in `from_file'

Relevant File Content:
----------------------
/opt/chef-repo/cookbooks/jockey/attributes/default.rb:

 23:  default['jockey']['spring']['webscripts']['config_path']                  = 'jockey'
 24:  # default['jockey']['share_config_custom_dev_override']               = 'false'
 25:  default['jockey']['share']['config']['custom_dev_signup_url']             = ''
 26:  default['jockey']['share']['config']['custom_dev_signup_email']           = ''
 27:  default['jockey']['share']['config']['custom_dev_ganalytics_code']        = ''
 28:
 29:  # # jockey
 30>> default['jockey']['db_name']                     = node[:ec2][:ext_data][:jockey_db_name]
 31:  default['jockey']['db_username']                 = 'jockey'
 32:  default['jockey']['db_password']                 = 'jockey'
 33:  default['jockey']['db_server']                   = 'localhost'
 34:  default['jockey']['db_port']                     = '3306'
 35:  default['jockey']['db_pool_min']                 = '3'
 36:  default['jockey']['db_pool_max']                 = '30'
 37:  default['jockey']['db_pool_initial']             = '3'
 38:  default['jockey']['jdbc_fetch_size']             = '150'
 39:  default['jockey']['dir_root']                    = '/var/lib/jockey/alf_data'

[2013-03-18T22:33:30+00:00] ERROR: Running exception handlers
[2013-03-18T22:33:30+00:00] ERROR: Exception handlers complete
[2013-03-18T22:33:30+00:00] FATAL: Stacktrace dumped to /var/cache/chef-solo/chef-stacktrace.out
[2013-03-18T22:33:30+00:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass

opt]# cat /var/cache/chef-solo/chef-stacktrace.out
Generated at 2013-03-18 22:33:30 +0000
NoMethodError: undefined method `[]' for nil:NilClass
/opt/chef-repo/cookbooks/jockey/attributes/default.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:192:in `block in load_attributes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:230:in `call'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:230:in `block (2 levels) in foreach_cookbook_load_segment'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:229:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:229:in `block in foreach_cookbook_load_segment'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:227:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:227:in `foreach_cookbook_load_segment'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:189:in `load_attributes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/run_context.rb:65:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/client.rb:198:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/client.rb:418:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/client.rb:176:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/application.rb:140:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/application/solo.rb:224:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/application/solo.rb:216:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/application/solo.rb:216:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/lib/chef/application.rb:72:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.2/bin/chef-solo:25:in `<top (required)>'
/usr/bin/chef-solo:23:in `load'
/usr/bin/chef-solo:23:in `<main>'

-------------

node[:ec2][:ext_data][:jockey_db_name] is loaded from a custom ohai plugin that should be loaded during compile phase.
running 'ohai -d /var/chef/ohai_plugins ec2' once the script is loaded yields the correct output.
If I use the ohai attribute directly in a template, or a recipe then the correct value is assigned. It is only failing to load when I try to assign it within the ./attributes/default.rb file.
I have assigned values further up the Mash, and just one level up @ node[:ec2][:ext_data] allows a complete chef-solo run, but the attribute is blank. So I assume the error above comes from the fact that node[:ec2][:ext_data] is an empty hash.

I am, however, perplexed that the Ohai data is not available when the default attributes file is loaded.

Tom


On 18 March 2013 19:44, AJ Christensen < " target="_blank"> > wrote:
Please post the full (debug) logs from Chef, not just the
exceptionally useless single line fatal exception.

Automatic attributes from ohai are loaded and merged to the node
before attributes from roles, environments *and* cookbooks, may even
be one of the first things Chef does.

What sets the node['ec2']['instance']['Env'] key ? An ohai plugin? Can
you publish it? Can you see it running successfully?

Can you point ohai at your plugins dir and execute it directly with ohai?

Cheers,

AJ

On 19 March 2013 03:52, Tom < "> > wrote:
> Ohai,
>
> I'm using chef-solo and I am loading some attributes into ohai - specifcally
> some custom ec2 data generated from tags and userdata.
>
> I'd like to be able to set some of the default attributes in my cookbook to
> the values in Ohai, but when I load a chef-solo run I am receiving the
> following error:
>
> [2013-03-18T14:45:36+00:00] FATAL: Stacktrace dumped to
> /var/cache/chef-solo/chef-stacktrace.out
>
> and it points to the cookbook attribute:
>
>  83>> default['jockey']['cluster_name']                         =
> node['ec2']['instance']['Env'].downcase
>
> I presume this is happening because Ohai has not been populated with my
> custom data by the time default attributes have been processed in the deep
> merge.
>
> Is there a better/different way I should be loading these attributes?
>
> Thanks for any help.
>
> Tom




Archive powered by MHonArc 2.6.16.

§