The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com
fact fqdn doesn't get set if domain fact isn't set
|Status:||Requires CLA to be signed||Start date:||03/09/2010|
|Keywords:||domain, fqdn||Affected Facter version:||1.6.3|
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:
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;–)
#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
- File fqdn.rb.patch added
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.
#6 Updated by Johan Huysmans almost 3 years ago
- File fqdn.rb.patch added
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 (
- 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?
#9 Updated by Ashley Penney 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