The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

Bug #3357

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

Added by Simon Hürlimann over 4 years ago. Updated over 1 year ago.

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

0%

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

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com

This ticket may be automatically exported to the FACT project on JIRA using the button below:


Description

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 https://bugs.launchpad.net/bugs/534773 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

History

#1 Updated by Simon Hürlimann over 4 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 over 4 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 - over 4 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 over 3 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 about 3 years ago

  • Target version changed from 1.6.0 to 144

#6 Updated by Johan Huysmans almost 3 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 almost 3 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:

https://projects.puppetlabs.com/contributor_licenses/sign

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 almost 3 years ago

I accepted the CLA.

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

#9 Updated by Anonymous over 2 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
else
nil
end
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('example.com')
+      Facter.fact(:fqdn).value.should == "host1.example.com"
+    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
+end

#10 Updated by Jeff Weiss over 2 years ago

  • Target version changed from 144 to 2.0.0

#11 Updated by Jeff Weiss over 2 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 about 2 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 over 1 year ago

  • Target version changed from 2.1.0 to 2.x

Also available in: Atom PDF