Aws and chef do not play nice

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:infrom_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:infrom_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:inload_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:ineach’
/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:incompile’
/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:insetup_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:inblock 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:inrun’
/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:inblock 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:inrun_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

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 <davidmontgomery@gmail.com

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 '

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 <
davidmontgomery@gmail.com> 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 <
davidmontgomery@gmail.com> 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 '

Part of the issue is that we have not yet found a reliable way in Ohai
to detect whether a machine is running in EC2. Hence the hints file.
However, creating the hints file in recipe code is not sufficient to
populate node['ec2'] because by that point, Ohai has already run.

You can create the hints file before you run Chef in a number of
ways, one of which is that "knife ec2 server create" will take a
--hint parameter.

  • Julian

On Wed, Nov 20, 2013 at 2:49 AM, Jordan Dea-Mattson
jdm-lists@dea-mattson.com wrote:

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

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

Speaking of this, I noticed that private VPC nodes don't seem to have
node['cloud'] or node['ec2'] defined. Is there a good workaround for this,
to always force these attributes to get loaded on those nodes? I bake my
own AMIs so if that helps, I'm fine with it.

On Wednesday, November 20, 2013, Julian C. Dunn wrote:

Part of the issue is that we have not yet found a reliable way in Ohai
to detect whether a machine is running in EC2. Hence the hints file.
However, creating the hints file in recipe code is not sufficient to
populate node['ec2'] because by that point, Ohai has already run.

You can create the hints file before you run Chef in a number of
ways, one of which is that "knife ec2 server create" will take a
--hint parameter.

  • Julian

On Wed, Nov 20, 2013 at 2:49 AM, Jordan Dea-Mattson
<jdm-lists@dea-mattson.com <javascript:;>> wrote:

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

--
[ Julian C. Dunn <jdunn@aquezada.com <javascript:;>> * Sorry,
I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

--

~~ StormeRider ~~

"Every world needs its heroes [...] They inspire us to be better than we
are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... http://bit.ly/Ps3uSS

On Wednesday, November 20, 2013 at 8:24 PM, Morgan Blackthorne wrote:

Speaking of this, I noticed that private VPC nodes don't seem to have node['cloud'] or node['ec2'] defined. Is there a good workaround for this, to always force these attributes to get loaded on those nodes? I bake my own AMIs so if that helps, I'm fine with it.
The hints file Julian describes below takes care of this

On Wednesday, November 20, 2013, Julian C. Dunn wrote:

Part of the issue is that we have not yet found a reliable way in Ohai
to detect whether a machine is running in EC2. Hence the hints file.
However, creating the hints file in recipe code is not sufficient to
populate node['ec2'] because by that point, Ohai has already run.

You can create the hints file before you run Chef in a number of
ways, one of which is that "knife ec2 server create" will take a
--hint parameter.

  • Julian

--
Daniel DeLeo

Wasn't there a way to reload ohai during a Chef run, e.g. after the hints
file has been placed?

I have seen this somewhere, but can't find it right now...

Cheers, Torben
On Nov 21, 2013 5:31 AM, "Daniel DeLeo" dan@kallistec.com wrote:

On Wednesday, November 20, 2013 at 8:24 PM, Morgan Blackthorne wrote:

Speaking of this, I noticed that private VPC nodes don't seem to have
node['cloud'] or node['ec2'] defined. Is there a good workaround for this,
to always force these attributes to get loaded on those nodes? I bake my
own AMIs so if that helps, I'm fine with it.

The hints file Julian describes below takes care of this

On Wednesday, November 20, 2013, Julian C. Dunn wrote:

Part of the issue is that we have not yet found a reliable way in Ohai
to detect whether a machine is running in EC2. Hence the hints file.
However, creating the hints file in recipe code is not sufficient to
populate node['ec2'] because by that point, Ohai has already run.

You can create the hints file before you run Chef in a number of
ways, one of which is that "knife ec2 server create" will take a
--hint parameter.

  • Julian

--
Daniel DeLeo

Hi,

I assume the ohai resource is what you had in mind:

http://docs.opscode.com/chef/resources.html#ohai

Cheers,

dsp


From: Torben Knerr [ukio@gmx.de]
Sent: 21 November 2013 09:08
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: aws and chef do not play nice

Wasn’t there a way to reload ohai during a Chef run, e.g. after the hints file has been placed?

I have seen this somewhere, but can’t find it right now…

Cheers, Torben

On Nov 21, 2013 5:31 AM, “Daniel DeLeo” <dan@kallistec.commailto:dan@kallistec.com> wrote:

On Wednesday, November 20, 2013 at 8:24 PM, Morgan Blackthorne wrote:

Speaking of this, I noticed that private VPC nodes don’t seem to have node[‘cloud’] or node[‘ec2’] defined. Is there a good workaround for this, to always force these attributes to get loaded on those nodes? I bake my own AMIs so if that helps, I’m fine with it.
The hints file Julian describes below takes care of this

On Wednesday, November 20, 2013, Julian C. Dunn wrote:
Part of the issue is that we have not yet found a reliable way in Ohai
to detect whether a machine is running in EC2. Hence the hints file.
However, creating the hints file in recipe code is not sufficient to
populate node[‘ec2’] because by that point, Ohai has already run.

You can create the hints file before you run Chef in a number of
ways, one of which is that “knife ec2 server create” will take a
–hint parameter.

  • Julian


Daniel DeLeo