[chef] Re: aws cookbook and tags


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: aws cookbook and tags
  • Date: Fri, 26 Jul 2013 08:38:24 -0700


On Thursday, July 25, 2013 at 4:38 PM, David Montgomery wrote:

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

Your error is in this line. Most likely `node['ec2']` is nil, so `node['ec2']['instance_id']` evaluates to `nil['instance_id']` which causes the error.

If you're using EC2 VPC, the cause of your problem is likely this: http://tickets.opscode.com/browse/OHAI-310

Try touching this file: /etc/chef/ohai/hints/ec2.json

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§