Detecting AWS VPC w/OHAI

Ohai, Chefs!

I’m a relative newbie with Chef and I need to put some conditional logic in
a recipe to branch on whether or not a node is running on AWS. I’ve seen
some search results that indicate ohai won’t pick up if a node is running
on AWS VPC (like mine are) without a specific hints file being added, but
I’m not sure how to do that. Is there some guidance or docs that detail how
to set things up so that my node attributes have something that indicates
whether or not the node is on AWS VPC? I’m launching nodes via Vagrant
w/Chef-Solo V11 and assume there’s some magic around the node.json and/or
ohai cookbook that’s needed.

Thanks!

David

You need to create /etc/chef/ohai/hints/ec2.json. It doesn’t need any content but the file itself needs to exist. We pass a provider attribute into our node attributes (vsphere, openstack, ec2, etc) and added this to our bootstrap file:

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

On Thursday, May 1, 2014 at 9:42 AM, David F. Severski wrote:

Ohai, Chefs!

I'm a relative newbie with Chef and I need to put some conditional logic in a recipe to branch on whether or not a node is running on AWS. I've seen some search results that indicate ohai won't pick up if a node is running on AWS VPC (like mine are) without a specific hints file being added, but I'm not sure how to do that. Is there some guidance or docs that detail how to set things up so that my node attributes have something that indicates whether or not the node is on AWS VPC? I'm launching nodes via Vagrant w/Chef-Solo V11 and assume there's some magic around the node.json and/or ohai cookbook that's needed.

Thanks!

David

Perfect! I was able to add a bit of shell script into the aws.user-data
portion of my Vagrantfile to get a similar effect. Thanks, Daniel!

David

On Thu, May 1, 2014 at 9:46 AM, Daniel Condomitti daniel@condomitti.comwrote:

You need to create /etc/chef/ohai/hints/ec2.json. It doesn’t need any
content but the file itself needs to exist. We pass a provider attribute
into our node attributes (vsphere, openstack, ec2, etc) and added this to
our bootstrap file:

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

On Thursday, May 1, 2014 at 9:42 AM, David F. Severski wrote:

Ohai, Chefs!

I'm a relative newbie with Chef and I need to put some conditional logic
in a recipe to branch on whether or not a node is running on AWS. I've seen
some search results that indicate ohai won't pick up if a node is running
on AWS VPC (like mine are) without a specific hints file being added, but
I'm not sure how to do that. Is there some guidance or docs that detail how
to set things up so that my node attributes have something that indicates
whether or not the node is on AWS VPC? I'm launching nodes via Vagrant
w/Chef-Solo V11 and assume there's some magic around the node.json and/or
ohai cookbook that's needed.

Thanks!

David