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
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 (http://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
But I am not using VPC.
Also..looking at hosted chef..I do not see ec2 attribute..yet I am using
ec2? Did ohai fail? I though chef would auto detect ec2.....
On Fri, Jul 26, 2013 at 11:38 PM, Daniel DeLeo dan@kallistec.com wrote:
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
zts
July 27, 2013, 5:53pm
4
Hi David,
On Sat, Jul 27, 2013 at 2:46 AM, David Montgomery <davidmontgomery@gmail.com
wrote:
But I am not using VPC.
Are you absolutely certain? If you started using a region in the last few
months, you'll automatically be creating instances in a VPC (see
http://aws.typepad.com/aws/2013/03/amazon-ec2-update-virtual-private-clouds-for-everyone.html
)
Also..looking at hosted chef..I do not see ec2 attribute..yet I am using
ec2? Did ohai fail? I though chef would auto detect ec2.....
Daniel's suggestion (creating the ohai hint) is the best thing to try.
Does it fix your problem?
If so, the problem is that Ohai cannot automatically detect that you are
running on EC2. Creating the hint file is the correct way to fix that.
Zac
This is what we use in our EC2/VPC bootstrap script
mkdir -p /etc/chef/ohai/hints && touch /etc/chef/ohai/hints/ec2.json
On Sat, Jul 27, 2013 at 1:53 PM, Zac Stevens zts@cryptocracy.com wrote:
Hi David,
On Sat, Jul 27, 2013 at 2:46 AM, David Montgomery <
davidmontgomery@gmail.com > wrote:
But I am not using VPC.
Are you absolutely certain? If you started using a region in the last few
months, you'll automatically be creating instances in a VPC (see
http://aws.typepad.com/aws/2013/03/amazon-ec2-update-virtual-private-clouds-for-everyone.html
)
Also..looking at hosted chef..I do not see ec2 attribute..yet I am using
ec2? Did ohai fail? I though chef would auto detect ec2.....
Daniel's suggestion (creating the ohai hint) is the best thing to try.
Does it fix your problem?
If so, the problem is that Ohai cannot automatically detect that you are
running on EC2. Creating the hint file is the correct way to fix that.
Zac