Sha256: 3f5e1d49720625eb168a7c57273ecbb4f44b6f5d6e0da98757327ee294034c32

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

# Fact: domain
#
# Purpose:
#   Return the host's primary DNS domain name.
#
# Resolution:
#   On UNIX (excluding Darwin), first try and use the hostname fact,
#   which uses the hostname system command, and then parse the output
#   of that.
#   Failing that it tries the dnsdomainname system command.
#   Failing that it uses /etc/resolv.conf and takes the domain from that, or as
#   a final resort, the search from that.
#   Otherwise returns nil.
#
#   On Windows uses the win32ole gem and winmgmts to get the DNSDomain value
#   from the Win32 networking stack.
#
# Caveats:
#

Facter.add(:domain) do
  setcode do
    # Get the domain from various sources; the order of these
    # steps is important

    if name = Facter::Util::Resolution.exec('hostname') and
      name =~ /.*?\.(.+$)/

      $1
    elsif domain = Facter::Util::Resolution.exec('dnsdomainname') and
      domain =~ /.+\..+/

      domain
    elsif FileTest.exists?("/etc/resolv.conf")
      domain = nil
      search = nil
      File.open("/etc/resolv.conf") { |file|
        file.each { |line|
          if line =~ /^\s*domain\s+(\S+)/
            domain = $1
          elsif line =~ /^\s*search\s+(\S+)/
            search = $1
          end
        }
      }
      next domain if domain
      next search if search
    end
  end
end

Facter.add(:domain) do
  confine :kernel => :windows
  setcode do
    require 'facter/util/wmi'
    domain = ""
    Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
      domain = nic.DNSDomain
      break
    }
    domain
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
supply_drop-0.11.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/facter-1.6.4/lib/facter/domain.rb
facter-1.6.4 lib/facter/domain.rb
facter-1.6.3 lib/facter/domain.rb