[chef] aws cookbook and tags


Chronological Thread 
  • From: David Montgomery < >
  • To:
  • Subject: [chef] aws cookbook and tags
  • Date: Fri, 26 Jul 2013 07:38:44 +0800

Hi,

Trying to add tags to ec2.  Using the below...and tryng ti use the example on http://community.opscode.com/cookbooks/aws

I get the below error......why?  s the example incorrect?

include_recipe "aws"
data_bag("my_data_bag")
db = data_bag_item("my_data_bag", "my")
aws = db[ node.chef_environment]['aws']
AWS_ACCESS_KEY_ID = aws['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = aws['AWS_SECRET_ACCESS_KEY']

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" => "Monitor",
        "node_name" => "#{node.name}",
        "environment" => node.chef_environment})
  action :update
end



================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/base/recipes/aws_monitor_tag.rb
================================================================================


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


Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/base/recipes/aws_monitor_tag.rb:8:in `from_file'


Relevant File Content:
----------------------
/var/chef/cache/cookbooks/base/recipes/aws_monitor_tag.rb:

  1:  include_recipe "aws"
  2:  data_bag("my_data_bag")
  3:  db = data_bag_item("my_data_bag", "my")
  4:  aws = db[ node.chef_environment]['aws']
  5:  AWS_ACCESS_KEY_ID = aws['AWS_ACCESS_KEY_ID']
  6:  AWS_SECRET_ACCESS_KEY = aws['AWS_SECRET_ACCESS_KEY']
  7: 
  8>> aws_resource_tag node['ec2']['instance_id'] do
  9:    aws_access_key aws['AWS_ACCESS_KEY_ID']
 10:    aws_secret_access_key aws['AWS_SECRET_ACCESS_KEY']
 11:    tags({"Name" => "Monitor",
 12:          "node_name" => "#{node.name}",
 13:          "environment" => node.chef_environment})
 14:    action :update
 15:  end 16: 


[2013-07-25T23:32:48+00:00] ERROR: Running exception handlers
[2013-07-25T23:32:48+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-07-25T23:32:48+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-07-25T23:32:49+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-07-25T23:32:49+00:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass




Archive powered by MHonArc 2.6.16.

§