Skip to content

Commit

Permalink
Merge pull request #1700 from rvaralda/2.x
Browse files Browse the repository at this point in the history
FACT-1822 - Fix get ec2_metadata on AWS EC2 5 generation for facter 2.x
  • Loading branch information
GabrielNagy authored Sep 30, 2019
2 parents 70f0e08 + 0f03e19 commit 8ff0fac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/facter/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Facter.define_fact(:ec2_metadata) do
define_resolution(:rest) do
confine do
Facter.value(:virtual).match /^(xen|kvm|nitro)/
Facter.value(:virtual).match /^(xen|kvm|nitro|ec2)/
end

@querier = Facter::EC2::Metadata.new
Expand All @@ -37,7 +37,7 @@
Facter.define_fact(:ec2_userdata) do
define_resolution(:rest) do
confine do
Facter.value(:virtual).match /^(xen|kvm|nitro)/
Facter.value(:virtual).match /^(xen|kvm|nitro|ec2)/
end

@querier = Facter::EC2::Userdata.new
Expand Down
4 changes: 4 additions & 0 deletions lib/facter/util/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def self.xen?
end
end

def self.ec2?
File.read("/sys/devices/virtual/dmi/id/bios_vendor") =~ /Amazon EC2/ rescue false
end

def self.kvm?
txt = if FileTest.exists?("/proc/cpuinfo")
File.read("/proc/cpuinfo")
Expand Down
4 changes: 4 additions & 0 deletions lib/facter/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
next "xenu" if FileTest.exists?("/proc/xen") || FileTest.exists?("/dev/xvda1")
end

if Facter::Util::Virtual.ec2?
next "ec2" if FileTest.exists?("/dev/nvme0")
end

next "virtualbox" if Facter::Util::Virtual.virtualbox?
next Facter::Util::Virtual.kvm_type if Facter::Util::Virtual.kvm?
next "rhev" if Facter::Util::Virtual.rhev?
Expand Down

0 comments on commit 8ff0fac

Please sign in to comment.