[chef] Re: Re: aws and chef do not play nice


Chronological Thread 
  • From: Jordan Dea-Mattson < >
  • To: " " < >
  • Subject: [chef] Re: Re: aws and chef do not play nice
  • Date: Tue, 19 Nov 2013 23:49:14 -0800

The issue is, I believe, that at the time you execute this recipe that node['ec2']['instance_id'] is not defined. This is the cause of your failure due to 'undefined method'.

This is a Ruby runtime exception and is not 'managed' by 'ignore_failure'.

I previously encountered a similar issue. It was due to Ohai not setting the 'instance_id' appropriately on first run and was tied to a particular version of Ohai.  What version of Chef and version of Ohai are you using?

The reason it executes successfully following your first run, is that Ohai is not properly setting the 'instance_id'.

Yours,

Jordan


On Tue, Nov 19, 2013 at 11:04 PM, David Montgomery < " target="_blank"> > wrote:
Just as bad..I take out the recipe out of the run list then after I boot then I place the recipe back and run again.  Then it works.  Why?




On Wed, Nov 20, 2013 at 2:37 PM, David Montgomery < " target="_blank"> > wrote:
Why oh why will this not work?  Even worse...I am ignore_failure true.   I included the aws recipe in the run list.




directory "/etc/chef/ohai/hints" do
  owner "root"
  group "root"
  recursive true
  action :create
end

file "/etc/chef/ohai/hints/ec2.json" do
  owner "root"
  group "root"
  action :create
end

aws_resource_tag node['ec2']['instance_id'] do
  aws_access_key aws['AWS_ACCESS_KEY_ID']
  aws_secret_access_key aws['AWS_SECRET_ACCESS_KEY']
  tags({"Name" => "#{node.name}",
        "node_name" => "#{node.name}",
        "environment" => node.chef_environment})
  action :update
  ignore_failure true
end


I included the aws recipe and yet aws_resource_tag node does not work.



 14: 
 15:  file "/etc/chef/ohai/hints/ec2.json" do
 16:    owner "root"
 17:    group "root"
 18:    action :create
 19:  end
 20: 
 21>> aws_resource_tag node['ec2']['instance_id'] do
 22:    aws_access_key aws['AWS_ACCESS_KEY_ID']
 23:    aws_secret_access_key aws['AWS_SECRET_ACCESS_KEY']
 24:    tags({"Name" => "#{node.name}",
 25:          "node_name" => "#{node.name}",
 26:          "environment" => node.chef_environment})
 27:    action :update
 28:    ignore_failure true
 29:  end 30: 


[2013-11-20T06:31:24+00:00] ERROR: Running exception handlers
[2013-11-20T06:31:24+00:00] ERROR: Creating JSON exception report
[2013-11-20T06:31:24+00:00] ERROR: Exception handlers complete
[2013-11-20T06:31:24+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-11-20T06:31:24+00:00] INFO: Sending resource update report (run-id: 039e995f-f8dc-463e-8dbb-94b01318178e)
[2013-11-20T06:31:25+00:00] ERROR: undefined method `[]' for nil:NilClass
[2013-11-20T06:31:25+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)




Generated at 2013-11-20 06:31:24 +0000
NoMethodError: undefined method `[]' for nil:NilClass
/var/chef/cache/cookbooks/bootstrap/recipes/aws_tag.rb:21:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/cookbook_version.rb:237:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/run_context.rb:151:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/run_context/cookbook_compiler.rb:139:in `block in compile_recipes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/run_context/cookbook_compiler.rb:137:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/run_context/cookbook_compiler.rb:137:in `compile_recipes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/run_context/cookbook_compiler.rb:74:in `compile'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/run_context.rb:86:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/client.rb:250:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/client.rb:498:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/client.rb:199:in `block in run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/client.rb:193:in `fork'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/client.rb:193:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/application.rb:208:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/application/client.rb:312:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/application/client.rb:304:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/application/client.rb:304:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/lib/chef/application.rb:66:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.0/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:23:in `load'
/usr/bin/chef-client:23:in `<main>'







Archive powered by MHonArc 2.6.16.

§