[chef] Re: Re: Re: Re: Re: Re: Re: AWS cookbook and the run list


Chronological Thread 
  • From: Daniel Condomitti < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: Re: Re: Re: AWS cookbook and the run list
  • Date: Mon, 26 Jan 2015 21:01:48 -0500

The problem is that there’s no reliable way to detect if you’re running in EC2, Rackspace Cloud or on bare metal hardware so hints are required[0]. We work around this by adding a provider attribute to our bootstrap JSON:

<% if ['openstack', 'ec2' ].include? first_boot['provider'] %>
mkdir -p /etc/chef/ohai/hints
touch /etc/chef/ohai/hints/<%= first_boot['provider'] %>.json
<% end %>

This is in our bootstrap template and our tools that kick off EC2 provisioning or vSphere VM creation sets provider to one of openstack, vsphere, ec2, or leaves it out if it’s bare metal.

Dan

[0] https://tickets.opscode.com/browse/OHAI-310

On Monday, January 26, 2015 at 8:47 PM, Greg Barker wrote:

I was hoping to avoid adding complexity to the run list by creating a new environment for EC2 and having to specify the env_run_lists in my base role. If I'm going down that route I would probably just put mycookbook::ec2_specific_
thing on the run_list there, which negates the necessity for using if node["ec2"].

It seems like a much simpler way to solve it would be something like:
if !node["ec2"].empty?
  include_recipe "mycookbook::ec2_specific_thing"
end
Or maybe relying on another attribute like node['cloud']['provider']?

Or am I crazy for trying to avoid env_run_lists here?

Greg

On Sat, Jan 24, 2015 at 9:46 AM, Julian C. Dunn < " target="_blank"> > wrote:
Ah yes. I missed the first part of Greg's email that stated that his
run_list contains recipe[aws::ec2_hints]. So... maybe not a good thing
to do when running under Vagrant :-)

- Julian

On Fri, Jan 23, 2015 at 7:29 PM, Daniel Condomitti
< "> > wrote:
> Julian,
>
> That’s the expected behavior, right? aws::ec2_hints adds the ec2 hints file
> for ohai which causes the node to be recognized as EC2 even if it isn’t. It
> doesn’t have any normal attributes populated but the node[‘ec2’] key exists.
>
> This is a CentOS 6.5 node running in VirtualBox
>
> # chef-shell -z
> ...
> chef > File.exists?('/etc/chef/ohai/hints/ec2.json')
>  => false
> chef > node['ec2']
>  => nil
> chef > exit
>
> # mkdir -p /etc/chef/ohai/hints
> # touch ohai/hints/ec2.json
> # chef-shell -z
>
> ....
> chef > File.exists?('/etc/chef/ohai/hints/ec2.json')
>  => true
> chef > node['ec2']
>  => #<Chef::Node::Attribute @normal={...}, @current_normal=nil,
> @default={...}, @current_default=nil, @override={...},
> @current_override=nil, @automatic={...}, @current_automatic={},
> @current_nesting_level=["ec2"], @auto_vivifiy_on_read=false,
> @set_unless_value_present=false, @set_type=nil, @has_been_read=false>
>
>
> On Friday, January 23, 2015 at 7:11 PM, Julian C. Dunn wrote:
>
> On Wed, Jan 21, 2015 at 10:07 PM, Greg Barker < "> > wrote:
>
> So I added this to my metadata.rb:
>
> depends 'aws'
>
> Added this to my run_list:
>
> "recipe[aws]",
> "recipe[aws::ec2_hints]",
>
> Added this to my recipe:
>
> if node["ec2"]
> include_recipe "mycookbook::ec2_specific_thing"
> end
>
> Works great when I ran it on an EC2 instance. But when I tried a `vagrant
> up` for a local VM, it hits an error in my ec2_specific_thing recipe. I
> thought it wasn't going to be executed at all though. Any ideas?
>
>
> That shouldn't happen. Can you paste the error?
>
> - Julian
>
>



--
[ Julian C. Dunn < "> >          * Sorry, I'm    ]
[ WWW: http://www.aquezada.com/staff/julian    * only Web 1.0  ]
[ gopher://sdf.org/1/users/keymaker/           * compliant!    ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9       ]





Archive powered by MHonArc 2.6.16.

§