Created
December 16, 2013 21:34
-
-
Save sodabrew/7994833 to your computer and use it in GitHub Desktop.
Add EC2 VPC facts to Facter 1.7, drop this file into `/etc/facter/facts.d/`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'facter/ec2' | |
# We might be in a VPC, which fails the normal EC2 MAC address checks | |
if !Facter.value('ec2_instance_id') && Facter.value('virtual') =~ /xen/ && Facter::Util::EC2.can_connect?(0.2) | |
Facter.debug "This is an EC2 VPC instance" | |
metadata | |
userdata | |
# vpc-id is in a newer metadata api rev than the usual EC2 facts | |
Facter.add(:ec2_vpc_id) do | |
setcode do | |
mac = open("http://169.254.169.254/2011-01-01/meta-data/mac").read.chomp | |
open("http://169.254.169.254/2011-01-01/meta-data/network/interfaces/macs/#{mac}/vpc-id").read.chomp | |
end | |
end | |
else | |
Facter.debug "Still not an EC2 host" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When, however, I dropped this into /usr/lib/ruby/site-ruby/1.8/facter, it worked fine.