Class: Puppet::Node::ServerFacts

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/node/server_facts.rb

Class Method Summary collapse

Class Method Details

.loadObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/puppet/node/server_facts.rb', line 4

def self.load
  server_facts = {}

  # Add our server Puppet Enterprise version, if available.
  pe_version_file = '/opt/puppetlabs/server/pe_version'
  if File.readable?(pe_version_file) and !File.zero?(pe_version_file)
    server_facts['pe_serverversion'] = File.read(pe_version_file).chomp
  end

  # Add our server version to the fact list
  server_facts["serverversion"] = Puppet.version.to_s

  # And then add the server name and IP
  { "servername" => "networking.fqdn",
    "serverip" => "networking.ip",
    "serverip6" => "networking.ip6" }.each do |var, fact|
    value = Puppet.runtime[:facter].value(fact)
    unless value.nil?
      server_facts[var] = value
    end
  end

  if server_facts["servername"].nil?
    host = Puppet.runtime[:facter].value('networking.hostname')
    if host.nil?
      Puppet.warning _("Could not retrieve fact servername")
    elsif domain = Puppet.runtime[:facter].value('networking.domain') # rubocop:disable Lint/AssignmentInCondition
      server_facts["servername"] = [host, domain].join(".")
    else
      server_facts["servername"] = host
    end
  end

  if server_facts["serverip"].nil? && server_facts["serverip6"].nil?
    Puppet.warning _("Could not retrieve either serverip or serverip6 fact")
  end

  server_facts
end