Sha256: eb75f4176affc166f20ce10e0be385c14cf32f8df230a36159ea2a5602daf8c4

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

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

        Facter.value(:hostname)
        next $domain if defined? $domain and ! $domain.nil?

        domain = Facter::Util::Resolution.exec('dnsdomainname')
        next domain if domain =~ /.+\..+/

        domain = Facter::Util::Resolution.exec('domainname')
        next domain if domain =~ /.+\..+/

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

Facter.add(:domain) do
    confine :kernel => :windows
    setcode do
        require 'win32ole'
        domain = ""
        wmi = WIN32OLE.connect("winmgmts://")
        query = "select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True"
        wmi.ExecQuery(query).each { |nic|
            domain = nic.DNSDomain
            break
        }
        domain
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
facter-1.5.7 lib/facter/domain.rb
facter-1.5.4 lib/facter/domain.rb
facter-1.5.3 lib/facter/domain.rb
facter-1.5.5 lib/facter/domain.rb
facter-1.5.6 lib/facter/domain.rb