Skip to content

Instantly share code, notes, and snippets.

@sodabrew
Created December 16, 2013 21:34
Show Gist options
  • Save sodabrew/7994833 to your computer and use it in GitHub Desktop.
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/`
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
@snetch
Copy link

snetch commented Feb 4, 2014

When, however, I dropped this into /usr/lib/ruby/site-ruby/1.8/facter, it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment