# Ohai Custom plugin for VPC

**URL:** <https://discourse.chef.io/t/ohai-custom-plugin-for-vpc/6234>\
**Category:** Chef Infra (archive)\
**Created:** [January 29, 2015, 9:09pm UTC](https://discourse.chef.io/t/ohai-custom-plugin-for-vpc/6234 "2015-01-29T21:09:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [January 29, 2015, 9:09pm UTC](https://discourse.chef.io/t/ohai-custom-plugin-for-vpc/6234/1 "2015-01-29T21:09:55Z")

</div>

I was trying to write an ohai plugin to add an attribute that tells me if  
I’m in a VPC or not. Not really sure what I’m doing. This code works on a  
real VPC instance, but on vagrant it’s not even setting is\_vpc. ☹

require ‘json’

Ohai.plugin(:EC2VPC) do  
provides “is\_vpc”

collect\_data do  
isa\_vpc = false  
if ec2.is\_a?(Hash)  
if ec2.has\_key?(‘network\_interfaces\_macs’)  
ec2[‘network\_interfaces\_macs’].each\_pair do |iface, data|  
if data.key?(‘vpc\_id’)  
isa\_vpc = true  
end  
end  
end  
end  
is\_vpc isa\_vpc  
end  
end

Doug.

---

<div class="post-metadata">

**Author:** ![jeffbyrnes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jeffbyrnes/32/1478_2.png) [@jeffbyrnes](https://discourse.chef.io/u/jeffbyrnes)\
**Post date:** [January 30, 2015, 7:21pm UTC](https://discourse.chef.io/t/ohai-custom-plugin-for-vpc/6234/2 "2015-01-30T19:21:27Z")

</div>

Doug,

Do you have this code published anywhere? Would love to help out with it if I can, but can’t tackle it just yet.

–  
Jeff Byrnes  
@thejeffbyrnes  
Lead DevOps Engineer  
EverTrue  
704.516.4628

On January 29, 2015 at 4:10:11 PM, Douglas Garstang ([doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)) wrote:

I was trying to write an ohai plugin to add an attribute that tells me if I’m in a VPC or not. Not really sure what I’m doing. This code works on a real VPC instance, but on vagrant it’s not even setting is\_vpc. ☹

require ‘json’

Ohai.plugin(:EC2VPC) do  
provides “is\_vpc”

collect\_data do  
isa\_vpc = false  
if ec2.is\_a?(Hash)  
if ec2.has\_key?(‘network\_interfaces\_macs’)  
ec2[‘network\_interfaces\_macs’].each\_pair do |iface, data|  
if data.key?(‘vpc\_id’)  
isa\_vpc = true  
end  
end  
end  
end  
is\_vpc isa\_vpc  
end  
end

Doug.

---

<div class="post-metadata">

**Author:** ![Douglas\_Garstang](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Douglas\_Garstang](https://discourse.chef.io/u/Douglas_Garstang)\
**Post date:** [January 30, 2015, 7:23pm UTC](https://discourse.chef.io/t/ohai-custom-plugin-for-vpc/6234/3 "2015-01-30T19:23:50Z")

</div>

Jeff,

No, but I've realised I can't use it anyway. Apparently data from custom  
ohai plugins is not available in the attributes.rb file. However, data from  
standard ohai plugins is. I don't think this is documented anywhere. I  
worked this out from observation. Since, at least in my case, I need to  
check if it's a vpc or not in the attributes file in order to set  
attributes used by upstream cookbooks, well, I just can't use it.

Doug.

On Fri, Jan 30, 2015 at 11:21 AM, Jeff Byrnes [jeff@evertrue.com](mailto:jeff@evertrue.com) wrote:

> Doug,
> 
> Do you have this code published anywhere? Would love to help out with it  
> if I can, but can’t tackle it just yet.
> 
> --  
> Jeff Byrnes  
> @thejeffbyrnes [http://twitter.com/thejeffbyrnes](http://twitter.com/thejeffbyrnes)  
> Lead DevOps Engineer  
> EverTrue [http://www.evertrue.com/](http://www.evertrue.com/)  
> 704.516.4628
> 
> On January 29, 2015 at 4:10:11 PM, Douglas Garstang (  
> [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)) wrote:
> 
> I was trying to write an ohai plugin to add an attribute that tells me  
> if I'm in a VPC or not. Not really sure what I'm doing. This code works on  
> a real VPC instance, but on vagrant it's not even setting is\_vpc. ☹
> 
> require 'json'
> 
> Ohai.plugin(:EC2VPC) do  
> provides "is\_vpc"
> 
> collect\_data do  
> isa\_vpc = false  
> if ec2.is\_a?(Hash)  
> if ec2.has\_key?('network\_interfaces\_macs')  
> ec2['network\_interfaces\_macs'].each\_pair do |iface, data|  
> if data.key?('vpc\_id')  
> isa\_vpc = true  
> end  
> end  
> end  
> end  
> is\_vpc isa\_vpc  
> end  
> end
> 
> Doug.

--  
Regards,

Douglas Garstang  
[http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
Cell: +1-805-340-5627

---

<div class="post-metadata">

**Author:** ![jeffbyrnes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jeffbyrnes/32/1478_2.png) [@jeffbyrnes](https://discourse.chef.io/u/jeffbyrnes)\
**Post date:** [January 30, 2015, 7:26pm UTC](https://discourse.chef.io/t/ohai-custom-plugin-for-vpc/6234/4 "2015-01-30T19:26:32Z")

</div>

Ah. Well, that’s good to know. Thanks Doug!

–  
Jeff Byrnes  
@thejeffbyrnes  
Lead DevOps Engineer  
EverTrue  
704.516.4628

On January 30, 2015 at 2:24:07 PM, Douglas Garstang ([doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)) wrote:

Jeff,

No, but I’ve realised I can’t use it anyway. Apparently data from custom ohai plugins is not available in the attributes.rb file. However, data from standard ohai plugins is. I don’t think this is documented anywhere. I worked this out from observation. Since, at least in my case, I need to check if it’s a vpc or not in the attributes file in order to set attributes used by upstream cookbooks, well, I just can’t use it.

Doug.

On Fri, Jan 30, 2015 at 11:21 AM, Jeff Byrnes [jeff@evertrue.com](mailto:jeff@evertrue.com) wrote:  
Doug,

Do you have this code published anywhere? Would love to help out with it if I can, but can’t tackle it just yet.

–  
Jeff Byrnes  
@thejeffbyrnes  
Lead DevOps Engineer  
EverTrue  
704.516.4628

On January 29, 2015 at 4:10:11 PM, Douglas Garstang ([doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)) wrote:

I was trying to write an ohai plugin to add an attribute that tells me if I’m in a VPC or not. Not really sure what I’m doing. This code works on a real VPC instance, but on vagrant it’s not even setting is\_vpc. ☹

require ‘json’

Ohai.plugin(:EC2VPC) do  
provides “is\_vpc”

collect\_data do  
isa\_vpc = false  
if ec2.is\_a?(Hash)  
if ec2.has\_key?(‘network\_interfaces\_macs’)  
ec2[‘network\_interfaces\_macs’].each\_pair do |iface, data|  
if data.key?(‘vpc\_id’)  
isa\_vpc = true  
end  
end  
end  
end  
is\_vpc isa\_vpc  
end  
end

Doug.

–  
Regards,

Douglas Garstang  
[http://www.linkedin.com/in/garstang](http://www.linkedin.com/in/garstang)  
Email: [doug.garstang@gmail.com](mailto:doug.garstang@gmail.com)  
Cell: +1-805-340-5627
