Skip to content

Instantly share code, notes, and snippets.

@jeffweiss
Forked from ploubser/gist:5213863
Last active December 15, 2015 10:58
Show Gist options
  • Save jeffweiss/5249169 to your computer and use it in GitHub Desktop.
Save jeffweiss/5249169 to your computer and use it in GitHub Desktop.
require 'facter/lsb'
f = File.open('/tmp/file', 'a')
Facter.add(:operatingsystem) do
confine :kernel => :sunos
setcode do "Solaris" end
end
Facter.add(:operatingsystem) do
confine :kernel => :linux
setcode do
f.puts "#{Time.now.inspect} - matched linux"
if Facter.value(:lsbdistid) == "Ubuntu"
"Ubuntu"
elsif FileTest.exists?("/etc/debian_version")
"Debian"
elsif FileTest.exists?("/etc/gentoo-release")
"Gentoo"
elsif FileTest.exists?("/etc/fedora-release")
"Fedora"
elsif FileTest.exists?("/etc/mandriva-release")
"Mandriva"
elsif FileTest.exists?("/etc/mandrake-release")
"Mandrake"
elsif FileTest.exists?("/etc/meego-release")
"MeeGo"
elsif FileTest.exists?("/etc/arch-release")
"Archlinux"
elsif FileTest.exists?("/etc/oracle-release")
"OracleLinux"
elsif FileTest.exists?("/etc/enterprise-release")
if FileTest.exists?("/etc/ovs-release")
"OVS"
else
"OEL"
end
elsif FileTest.exists?("/etc/arch-release")
"Arch"
elsif FileTest.exists?("/etc/vmware-release")
"VMWareESX"
elsif FileTest.exists?("/etc/redhat-release")
txt = File.read("/etc/redhat-release")
if txt =~ /centos/i
"CentOS"
elsif txt =~ /CERN/
"SLC"
elsif txt =~ /scientific/i
"Scientific"
elsif txt =~ /^cloudlinux/i
"CloudLinux"
elsif txt =~ /^Parallels Server Bare Metal/i
"PSBM"
elsif txt =~ /Ascendos/i
"Ascendos"
else
"RedHat"
end
elsif FileTest.exists?("/etc/SuSE-release")
txt = File.read("/etc/SuSE-release")
if txt =~ /^SUSE LINUX Enterprise Server/i
"SLES"
elsif txt =~ /^SUSE LINUX Enterprise Desktop/i
"SLED"
elsif txt =~ /^openSUSE/i
"OpenSuSE"
else
"SuSE"
end
elsif FileTest.exists?("/etc/bluewhite64-version")
"Bluewhite64"
elsif FileTest.exists?("/etc/slamd64-version")
"Slamd64"
elsif FileTest.exists?("/etc/slackware-version")
"Slackware"
elsif FileTest.exists?("/etc/alpine-release")
"Alpine"
elsif Facter.value(:lsbdistdescription) =~ /Amazon Linux/
"Amazon"
end
end
end
Facter.add(:operatingsystem) do
confine :kernel => "VMkernel"
setcode do
f.puts "#{Time.now.inspect} - matched VMkernel"
"ESXi"
end
end
Facter.add(:operatingsystem) do
# Default to just returning the kernel as the operating system
setcode do
f.puts "#{Time.now.inspect} - matched default"
Facter[:kernel].value
end
end
f.puts "Value of operatingsystem #{Facter.value('operatingsystem')}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment