[Pkg-puppet-devel] [PATCH 3/4] fixes #2573, #2085, #1291 - fixes domain and fqdn facts resolution

Ohad Levy ohad.levy at infineon.com
Fri Jun 25 20:34:55 UTC 2010


This patch removes the relationship between the domain fact and LDAP/NIS domains.
domain fact relates to DNS domain - this will avoid the confusion caused
by the LDAP/NIS domain (which might be different to the DNS domain name).
Additionally, if hostname is already in long form, it won't try to build
the fqdn fact from hostname and domain.

Signed-off-by: Stig Sandbeck Mathisen <ssm at debian.org>
---
 lib/facter/domain.rb   |    8 ++++----
 lib/facter/fqdn.rb     |    4 ++++
 lib/facter/hostname.rb |    7 ++++---
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb
index b1bba4d..5dfead0 100644
--- a/lib/facter/domain.rb
+++ b/lib/facter/domain.rb
@@ -4,14 +4,14 @@ Facter.add(:domain) do
         # steps is important
 
         Facter.value(:hostname)
-        next $domain if defined? $domain and ! $domain.nil?
+        # try to fetch the domain from hostname if long hostname is used.
+        if defined? $fqdn and $fqdn =~ /^([\w-]+)\.(.+)$/
+          next $2
+        end
 
         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
diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb
index 5ebc5f5..6271995 100644
--- a/lib/facter/fqdn.rb
+++ b/lib/facter/fqdn.rb
@@ -1,5 +1,9 @@
 Facter.add(:fqdn) do
     setcode do
+        # try to fetch the fqdn from hostname if long hostname is used.
+        Facter.value(:hostname)
+        next $fqdn if defined? $fqdn and ! $fqdn.nil?
+
         host = Facter.value(:hostname)
         domain = Facter.value(:domain)
         if host and domain
diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb
index 188efa4..c3ca968 100644
--- a/lib/facter/hostname.rb
+++ b/lib/facter/hostname.rb
@@ -1,12 +1,13 @@
 Facter.add(:hostname, :ldapname => "cn") do
     setcode do
+        require 'socket'
         hostname = nil
-        name = Facter::Util::Resolution.exec('hostname') or nil
+        name = Socket.gethostbyname(Socket.gethostname).first
         if name
             if name =~ /^([\w-]+)\.(.+)$/
                 hostname = $1
-                # the Domain class uses this
-                $domain = $2
+                # the FQDN/Domain facts use this
+                $fqdn = name
             else
                 hostname = name
             end
-- 
1.7.0.4




More information about the Pkg-puppet-devel mailing list