(#7484) Domain Fact should handle TLD
Before this commit, using hostname -f was opt-out. With this commit
it has been changed to be opt-in, to prevent problems on certain
operating systems like Solaris and HP-UX.
Hailee Kenney
12 years ago
22 | 22 |
# Get the domain from various sources; the order of these
|
23 | 23 |
# steps is important
|
24 | 24 |
|
25 | |
hostname_command = (Facter.value(:kernel) =~ /SunOS/i) ? 'hostname' : 'hostname -f'
|
|
25 |
# In some OS 'hostname -f' will change the hostname to '-f'
|
|
26 |
# We know that Solaris and HP-UX exhibit this behavior
|
|
27 |
# On good OS, 'hostname -f' will return the FQDN which is preferable
|
|
28 |
# Due to dangerous behavior of 'hostname -f' on old OS, we will explicitly opt-in
|
|
29 |
# 'hostname -f' --hkenney May 9, 2012
|
|
30 |
hostname_command = 'hostname'
|
|
31 |
can_do_hostname_f = Regexp.union /Linux/i, /FreeBSD/i, /Darwin/i
|
|
32 |
hostname_command = 'hostname -f' if Facter.value(:kernel) =~ can_do_hostname_f
|
|
33 |
|
26 | 34 |
|
27 | 35 |
if name = Facter::Util::Resolution.exec(hostname_command) \
|
28 | 36 |
and name =~ /.*?\.(.+$)/
|
7 | 7 |
:solaris => {:kernel => "SunOS", :hostname_command => "hostname"},
|
8 | 8 |
:darwin => {:kernel => "Darwin", :hostname_command => "hostname -f"},
|
9 | 9 |
:freebsd => {:kernel => "FreeBSD", :hostname_command => "hostname -f"},
|
|
10 |
:hpux => {:kernel => "HP-UX", :hostname_command => "hostname"},
|
10 | 11 |
}.each do |key, nested_hash|
|
11 | 12 |
|
12 | 13 |
describe "on #{key}" do
|