Skip to content

Commit

Permalink
Fixes #34883: Show output of facter and hostname during check
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms authored and evgeni committed May 10, 2022
1 parent afe1e2d commit f5b9904
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions checks/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

require 'English'

def error_exit(message, code)
$stderr.puts message
exit code
end

MISSING = "Command 'facter' does not exist in system executable path
Make sure the above command is installed and executable in your system. ".freeze

ENV['PATH'] = ENV['PATH'].split(File::PATH_SEPARATOR).concat(['/opt/puppetlabs/bin']).join(File::PATH_SEPARATOR)

system("which facter > /dev/null 2>&1")
error_exit(MISSING, 3) if $CHILD_STATUS.exitstatus == 1

facter_fqdn = `facter fqdn`.chomp
hostname_f = `hostname -f`.chomp

BASE = "If needed, change the hostname permanently via the
'hostname' or 'hostnamectl set-hostname' command
and editing the appropriate configuration file.
Expand All @@ -15,38 +32,22 @@
The fully qualified hostname must be the first entry on the line".freeze

DIFFERENT = "Output of 'facter fqdn' is different from 'hostname -f'
DIFFERENT = "Output of 'facter fqdn' (#{facter_fqdn}) is different from 'hostname -f' (#{hostname_f})
Make sure above command gives the same output. ".freeze

INVALID = "Output of 'hostname -f' does not seems to be valid FQDN
INVALID = "Output of 'hostname -f' (#{hostname_f}) does not seems to be valid FQDN
Make sure above command gives fully qualified domain name. At least one
dot must be present and underscores are not allowed. ".freeze

MISSING = "Command 'facter' does not exist in system executable path
Make sure the above command is installed and executable in your system. ".freeze

UPCASE = 'The hostname contains a capital letter.
This is not supported. Please modify the hostname to be all lowercase. '.freeze

def error_exit(message, code)
$stderr.puts message
exit code
end

ENV['PATH'] = ENV['PATH'].split(File::PATH_SEPARATOR).concat(['/opt/puppetlabs/bin']).join(File::PATH_SEPARATOR)
UPCASE = "The hostname (#{facter_fqdn}) contains a capital letter.
system("which facter > /dev/null 2>&1")
error_exit(MISSING, 3) if $CHILD_STATUS.exitstatus == 1

facter_fqdn = `facter fqdn`.chomp
This is not supported. Please modify the hostname to be all lowercase. ".freeze

# Check that facter actually has a value that matches the hostname.
# This should always be true for facter >= 1.7
error_exit(DIFFERENT + BASE, 1) if facter_fqdn != `hostname -f`.chomp
error_exit(DIFFERENT + BASE, 1) if facter_fqdn != hostname_f
# Every FQDN should have at least one dot
error_exit(INVALID + BASE, 2) unless facter_fqdn.include?('.')
# Per https://bugzilla.redhat.com/show_bug.cgi?id=1205960 check for underscores
Expand Down

0 comments on commit f5b9904

Please sign in to comment.