Module: PuppetRepl::Support::Facts

Included in:
PuppetRepl::Support
Defined in:
lib/puppet-repl/support/facts.rb

Instance Method Summary collapse

Instance Method Details

#default_facter_versionObject

return the correct supported version of facter facts



21
22
23
24
25
26
27
# File 'lib/puppet-repl/support/facts.rb', line 21

def default_facter_version
  if Gem::Version.new(Puppet.version) >= Gem::Version.new(4.4)
    '/^3\.1/'
  else
    '/^2\.4/'
  end
end

#default_facterdb_filterObject



12
13
14
# File 'lib/puppet-repl/support/facts.rb', line 12

def default_facterdb_filter
  "operatingsystem=#{facter_os_name} and operatingsystemrelease=#{facter_os_version} and architecture=x86_64 and facterversion=#{facter_version}"
end

#default_factsObject



59
60
61
62
63
64
65
66
# File 'lib/puppet-repl/support/facts.rb', line 59

def default_facts
  unless @facts
    values = Hash[ node_facts.map { |k, v| [k.to_s, v] } ]
    name = values['fqdn']
    @facts ||= Puppet::Node::Facts.new(name, values)
  end
  @facts
end

#dynamic_facterdb_filterObject

allow the user to specify the facterdb filter



8
9
10
# File 'lib/puppet-repl/support/facts.rb', line 8

def dynamic_facterdb_filter
  ENV['REPL_FACTERDB_FILTER'] || default_facterdb_filter
end

#facter_os_nameObject



29
30
31
# File 'lib/puppet-repl/support/facts.rb', line 29

def facter_os_name
  ENV['REPL_FACTER_OS_NAME'] || 'Fedora'
end

#facter_os_versionObject



33
34
35
# File 'lib/puppet-repl/support/facts.rb', line 33

def facter_os_version
  ENV['REPL_FACTER_OS_VERSION'] || '23'
end

#facter_versionObject



16
17
18
# File 'lib/puppet-repl/support/facts.rb', line 16

def facter_version
  ENV['REPL_FACTER_VERSION'] || default_facter_version
end

#node_factsObject

uses facterdb (cached facts) and retrives the facts given a filter creates a new facts object we could also use fact_merge to get real facts from the real system or puppetdb



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet-repl/support/facts.rb', line 44

def node_facts
  node_facts = FacterDB.get_facts(dynamic_facterdb_filter).first
  if node_facts.nil?
    message = <<-EOS
Using filter: #{facterdb_filter}
Bad FacterDB filter, please change the filter so it returns a result set.
See https://github.com/camptocamp/facterdb/#with-a-string-filter
    EOS
    raise PuppetRepl::Exception::BadFilter.new(:message => message)
  end
  # fix for when --show-legacy facts are not part of the facter 3 fact set
  node_facts[:fqdn] = node_facts[:networking].fetch('fqdn',nil) unless node_facts[:fqdn]
  node_facts
end

#server_factsObject



68
69
70
71
72
73
74
# File 'lib/puppet-repl/support/facts.rb', line 68

def server_facts
  data = {}
  data["servername"] = Facter.value("fqdn") || Facter.value('networking')['fqdn']
  data['serverip'] = Facter.value("ipaddress")
  data["serverversion"] = Puppet.version.to_s
  data
end

#set_facts(value) ⇒ Object



37
38
39
# File 'lib/puppet-repl/support/facts.rb', line 37

def set_facts(value)
  @facts = value
end