Determine inside VPC


#1

I’m trying to use ohai to determine if my instance is inside a VPC. There’s
a key nested down there under node[‘ec2’][‘network_interfaces_macs’] when
this is the case, called vpc_id, but my ruby is horrible and I’m having
trouble fetching it. For reasons I don’t understand ohai reports this is a
dictionary, but when I attempt to iterate over it inside a chef recipe,
it’s an array.

Is there an easy/better way to determine in chef if your ec2 instance is
inside a VPC?

Doug


#2

ISTR that you’ll have issues with VPC if you don’t have the Ohai hint
loaded. That said, the Ohai hint might actually contain exactly what you’re
looking for to key off of. We run nothing outside of VPC at this point, so
I can’t help beyond that.


~~ 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 Mon, Jan 26, 2015 at 11:38 AM, Douglas Garstang doug.garstang@gmail.com
wrote:

I’m trying to use ohai to determine if my instance is inside a VPC.
There’s a key nested down there under
node[‘ec2’][‘network_interfaces_macs’] when this is the case, called
vpc_id, but my ruby is horrible and I’m having trouble fetching it. For
reasons I don’t understand ohai reports this is a dictionary, but when I
attempt to iterate over it inside a chef recipe, it’s an array.

Is there an easy/better way to determine in chef if your ec2 instance is
inside a VPC?

Doug


#3

Perhaps this will work for you?
vpc_id = nil
node[‘ec2’][‘network_interfaces_macs’].each_pair do |iface, data|
vpc_id = data[‘vpc_id’] if data.key?(‘vpc_id’)
end

On Mon, Jan 26, 2015 at 2:38 PM, Douglas Garstang doug.garstang@gmail.com
wrote:

I’m trying to use ohai to determine if my instance is inside a VPC.
There’s a key nested down there under
node[‘ec2’][‘network_interfaces_macs’] when this is the case, called
vpc_id, but my ruby is horrible and I’m having trouble fetching it. For
reasons I don’t understand ohai reports this is a dictionary, but when I
attempt to iterate over it inside a chef recipe, it’s an array.

Is there an easy/better way to determine in chef if your ec2 instance is
inside a VPC?

Doug