Sha256: 8bd61ff3c3dc0eb32ccb2d8b4e60af7a1f7f2d01f0014a2f872b382f050ba86e

Contents?: true

Size: 897 Bytes

Versions: 15

Compression:

Stored size: 897 Bytes

Contents

require 'facter/util/ec2'
require 'open-uri'

def metadata(id = "")
  open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read.
    split("\n").each do |o|
    key = "#{id}#{o.gsub(/\=.*$/, '/')}"
    if key[-1..-1] != '/'
      value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read.
        split("\n")
      symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym
      Facter.add(symbol) { setcode { value.join(',') } }
    else
      metadata(key)
    end
  end
end

def userdata()
  begin
    value = open("http://169.254.169.254/2008-02-01/user-data/").read.split
    Facter.add(:ec2_userdata) { setcode { value } }
  rescue OpenURI::HTTPError
  end
end

if (Facter::Util::EC2.has_euca_mac? || Facter::Util::EC2.has_openstack_mac? || 
    Facter::Util::EC2.has_ec2_arp?) && Facter::Util::EC2.can_connect?

  metadata
  userdata
else
  Facter.debug "Not an EC2 host"
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
facter-1.6.14 lib/facter/ec2.rb
facter-1.6.14.rc1 lib/facter/ec2.rb
facter-1.6.13 lib/facter/ec2.rb
facter-1.6.13.rc1 lib/facter/ec2.rb
facter-1.6.12 lib/facter/ec2.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/facter-1.6.11/lib/facter/ec2.rb
facter-1.6.12.rc2 lib/facter/ec2.rb
facter-1.6.12.rc1 lib/facter/ec2.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/facter-1.6.11/lib/facter/ec2.rb
facter-1.6.11 lib/facter/ec2.rb
facter-1.6.10 lib/facter/ec2.rb
facter-1.6.9 lib/facter/ec2.rb
facter-1.6.8 lib/facter/ec2.rb
facter-1.6.7 lib/facter/ec2.rb
facter-1.6.6 lib/facter/ec2.rb