Advertisement
Guest User

Facter operatingsystem

a guest
Sep 24th, 2013
1,636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.79 KB | None | 0 0
  1. # Fact: operatingsystem
  2. #
  3. # Purpose: Return the name of the operating system.
  4. #
  5. # Resolution:
  6. #   If the kernel is a Linux kernel, check for the existence of a selection of
  7. #   files in /etc/ to find the specific flavour.
  8. #   On SunOS based kernels, return Solaris.
  9. #   On systems other than Linux, use the kernel value.
  10. #
  11. # Caveats:
  12. #
  13.  
  14. Facter.add(:operatingsystem) do
  15.   confine :kernel => :sunos
  16.   setcode do
  17.     if FileTest.exists?("/etc/debian_version")
  18.       "Nexenta"
  19.     else
  20.       "Solaris"
  21.     end
  22.   end
  23. end
  24.  
  25. Facter.add(:operatingsystem) do
  26.   confine :kernel => :linux
  27.   setcode do
  28.     if Facter.value(:lsbdistid) == "Ubuntu"
  29.        "Ubuntu"
  30.     elsif FileTest.exists?("/etc/debian_version")
  31.       "Debian"
  32.     elsif FileTest.exists?("/etc/gentoo-release")
  33.       "Gentoo"
  34.     elsif FileTest.exists?("/etc/fedora-release")
  35.       "Fedora"
  36.     elsif FileTest.exists?("/etc/mandriva-release")
  37.       "Mandriva"
  38.     elsif FileTest.exists?("/etc/mandrake-release")
  39.       "Mandrake"
  40.     elsif FileTest.exists?("/etc/meego-release")
  41.       "MeeGo"
  42.     elsif FileTest.exists?("/etc/arch-release")
  43.       "Archlinux"
  44.     elsif FileTest.exists?("/etc/oracle-release")
  45.       "OracleLinux"
  46.     elsif FileTest.exists?("/etc/enterprise-release")
  47.       if FileTest.exists?("/etc/ovs-release")
  48.         "OVS"
  49.       else
  50.         "OEL"
  51.       end
  52.     elsif FileTest.exists?("/etc/vmware-release")
  53.       "VMWareESX"
  54.     elsif FileTest.exists?("/etc/redhat-release")
  55.       txt = File.read("/etc/redhat-release")
  56.       if txt =~ /centos/i
  57.         "CentOS"
  58.       elsif txt =~ /CERN/
  59.         "SLC"
  60.       elsif txt =~ /scientific/i
  61.         "Scientific"
  62.       elsif txt =~ /^cloudlinux/i
  63.         "CloudLinux"
  64.       elsif txt =~ /^Parallels Server Bare Metal/i
  65.         "PSBM"
  66.       elsif txt =~ /Ascendos/i
  67.         "Ascendos"
  68.       else
  69.         "RedHat"
  70.       end
  71.     elsif FileTest.exists?("/etc/SuSE-release")
  72.       txt = File.read("/etc/SuSE-release")
  73.       if txt =~ /^SUSE LINUX Enterprise Server/i
  74.         "SLES"
  75.       elsif txt =~ /^SUSE LINUX Enterprise Desktop/i
  76.         "SLED"
  77.       elsif txt =~ /^openSUSE/i
  78.         "OpenSuSE"
  79.       else
  80.         "SuSE"
  81.       end
  82.     elsif FileTest.exists?("/etc/bluewhite64-version")
  83.       "Bluewhite64"
  84.     elsif FileTest.exists?("/etc/slamd64-version")
  85.       "Slamd64"
  86.     elsif FileTest.exists?("/etc/slackware-version")
  87.       "Slackware"
  88.     elsif FileTest.exists?("/etc/alpine-release")
  89.       "Alpine"
  90.     elsif FileTest.exists?("/etc/system-release")
  91.       "Amazon"
  92.     end
  93.   end
  94. end
  95.  
  96. Facter.add(:operatingsystem) do
  97.   confine :kernel => "VMkernel"
  98.   setcode do
  99.     "ESXi"
  100.   end
  101. end
  102.  
  103. Facter.add(:operatingsystem) do
  104.   # Default to just returning the kernel as the operating system
  105.   setcode do Facter[:kernel].value end
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement