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 |
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
Whenever I try to run this, I get:
/usr/lib/ruby/site_ruby/1.8/facter/util/ec2.rb:6: uninitialized constant Facter (NameError)
from /usr/lib/ruby/site_ruby/1.8/facter/ec2.rb:1:in
require' from /usr/lib/ruby/site_ruby/1.8/facter/ec2.rb:1 from ./ec2_vpc.rb:2:in
require'from ./ec2_vpc.rb:2
When I run a couple commands in irb (command line ruby), I get this:
irb(main):001:0> require 'facter/ec2'
NameError: uninitialized constant Facter
from /usr/lib/ruby/site_ruby/1.8/facter/util/ec2.rb:6
from /usr/lib/ruby/site_ruby/1.8/facter/ec2.rb:1:in
require' from /usr/lib/ruby/site_ruby/1.8/facter/ec2.rb:1 from (irb):1:in
require'from (irb):1
from �:0
irb(main):002:0> require 'facter/util/ec2'
NameError: uninitialized constant Facter
from /usr/lib/ruby/site_ruby/1.8/facter/util/ec2.rb:6
from (irb):2:in `require'
from (irb):2
from �:0
In /usr/lib/ruby/site_ruby/1.8/facter/util/ec2.rb , it fails on the line that says "module Facter::Util::EC2"
Seems like this script requires facter/ec2, which requires facter/util/ec2, which fails for no apparent darn reason.