The Puppet Labs Issue Tracker has Moved:

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using See the following page for information on filing tickets with JIRA:

Bug #3357

fact fqdn doesn't get set if domain fact isn't set

Added by Simon Hürlimann about 6 years ago. Updated about 3 years ago.

Status:Requires CLA to be signedStart date:03/09/2010
Priority:NormalDue date:
Assignee:-% Done:


Target version:2.x
Keywords:domain, fqdn Affected Facter version:1.6.3

We've Moved!

Ticket tracking is now hosted in JIRA:


If the domain fact doesn’t get a value (see #3356) the fqdn isn’t set either. But it should probably be just the hostname in this case.

Think may break in very interesting ways when using fqdn in your pupper recipes, but it won’t be set. See as an example;–)

fqdn.rb.patch Magnifier - Patch for fqdn.rb. Allow it to returns the host instead of nil. (281 Bytes) Julien GEORGES, 02/09/2011 02:57 pm

fqdn.rb.patch Magnifier - Alternative patch (303 Bytes) Johan Huysmans, 11/16/2011 06:02 am


#1 Updated by Simon Hürlimann about 6 years ago

Using something like Facter::Util::Resolution.exec(‘hostname -f’) might be even closer to reality than simply joining two facts. But it won’t be as portable, though…

#2 Updated by James Turnbull about 6 years ago

  • Category set to library
  • Status changed from Unreviewed to Needs Decision
  • Assignee set to Paul Nasrat
  • Target version set to 1.6.0

Paul – thoughts?

#3 Updated by micah - almost 6 years ago

If facter cannot figure out the fqdn, wouldn’t it be better to have it set as ‘nil’, rather than set it to something other than what it is? In otherwords, don’t we want facter representing the real state of the system, not making things up? If there is no fqdn for the host configured, it probably should be represented as no fqdn configured for the system.

Afterall, what if you wanted to find all the systems that had no fqdn set, and fix them. You would only be able to do that if the fqdn was set to ‘nil’

#4 Updated by Julien GEORGES about 5 years ago

In the current use of facter, no fqdn set means no hostname or domain set. In order to find all the machines with no fqdn set, you can do the same search with the domain not set.

For me it’s important that the fqdn returns something because its value is used in many templates. On some nodes, the fqdn will only be its hostname and on other nodes it will be hostname.domain but you will still be able to configure your nodes.

#5 Updated by Michael Stahnke almost 5 years ago

  • Target version changed from 1.6.0 to 144

#6 Updated by Johan Huysmans over 4 years ago

The fqdn is the host + domain. If the domain is empty the fqdn is only the host, and thus not “nil”.

I added an alternative patch.

When host and domain is available, fqdn = host + “.” + domain
When only the host is available, fqdn = host
When both host and domain are not set, fqdn = nil

#7 Updated by Ken Barber over 4 years ago

  • Status changed from Needs Decision to Requires CLA to be signed
  • Assignee deleted (Paul Nasrat)
  • Affected Facter version set to 1.6.3

Johan thanks for this – can you please read and sign the CLA:

We’ll need this before we can accept your code.

Also – we’ll probably want some rspec tests to avoid regression. Are you able to do this?

#8 Updated by Johan Huysmans over 4 years ago

I accepted the CLA.

I’m sorry, but I’m not familiar with the rspec tests.

#9 Updated by Anonymous about 4 years ago

I’ve never written an rspec before but I figured it’s a good enough way to play around with ruby:

diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb
index 68597f3..48d0953 100644
--- a/lib/facter/fqdn.rb
+++ b/lib/facter/fqdn.rb
@@ -15,6 +15,8 @@ Facter.add(:fqdn) do
domain = Facter.value(:domain)
if host and domain
[host, domain].join(".")
+    elsif host
+      host
diff --git a/spec/unit/fqdn_spec.rb b/spec/unit/fqdn_spec.rb
new file mode 100755
index 0000000..fbfe2a5
--- /dev/null
+++ b/spec/unit/fqdn_spec.rb
@@ -0,0 +1,32 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+describe "Fqdn facts" do
+  describe "on linux" do
+    before do
+      Facter.fact(:kernel).stubs(:value).returns("Linux")
+      Facter.fact(:kernelrelease).stubs(:value).returns("2.6")
+    end
+    it "should join host and domain together" do
+      Facter.fact(:hostname).stubs(:value).returns('host1')
+      Facter.fact(:domain).stubs(:value).returns('')
+      Facter.fact(:fqdn).value.should == ""
+    end
+    it "should return just host if domain is missing" do
+      Facter.fact(:hostname).stubs(:value).returns('host1')
+      Facter.fact(:domain).stubs(:value).returns(nil)
+      Facter.fact(:fqdn).value.should == "host1"
+    end
+    it "should return nil if both host and domain are missing" do
+      Facter.fact(:hostname).stubs(:value).returns(nil)
+      Facter.fact(:domain).stubs(:value).returns(nil)
+      Facter.fact(:fqdn).value.should == nil
+    end
+  end

#10 Updated by Jeff Weiss almost 4 years ago

  • Target version changed from 144 to 2.0.0

#11 Updated by Jeff Weiss almost 4 years ago

  • Target version changed from 2.0.0 to 2.1.0

Ashley, we would like to be able to incorporate this change, but we need the CLA signed.

#12 Updated by Anonymous almost 4 years ago

Sorry for being so slow on this, I never saw this update – I’ve just gone and signed it.

#13 Updated by eric sorenson about 3 years ago

  • Target version changed from 2.1.0 to 2.x

Also available in: Atom PDF