(#20582) Restore facter_dot_d to stdlib for PE users
Without this patch Puppet Enterprise users who install the most recent version of stdlib lose the ability to resolve certain facts critical to the operation of Puppet Enterprise. These facts are defined externally in the file `/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt`. As an example, Puppet Enterprise catalogs fail to compile if the `fact_stomp_server`, and `fact_stomp_port` facts are not defined. `facter_dot_d` was removed from stdlib version 4 because Facter version 1.7 now supports external facts defined in `/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt`. Puppet Enterprise does not yet include Facter 1.7, however. The most recent PE release, 2.8.1, includes Facter 1.6.17. With this version of Facter, users who replace the version of stdlib that ships with PE with the most recent version from the Forge will lose the ability to resolve facts from `/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt`. This patch addresses the problem by detecting if Facter version < 1.7 is loaded. If so, then the facter_dot_d.rb facts will be defined using the stdlib custom fact. If Facter >= 1.7 is being used then stdlib will not define external facts.
This commit is contained in:
parent
77991d3a77
commit
3b887c880c
2 changed files with 86 additions and 7 deletions
|
@ -181,12 +181,22 @@ class Facter::Util::DotD
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Facter::Util::DotD.new("/etc/facter/facts.d").create
|
|
||||||
Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create
|
|
||||||
|
|
||||||
# Windows has a different configuration directory that defaults to a vendor
|
mdata = Facter.version.match(/(\d+)\.(\d+)\.(\d+)/)
|
||||||
# specific sub directory of the %COMMON_APPDATA% directory.
|
if mdata
|
||||||
if Dir.const_defined? 'COMMON_APPDATA' then
|
(major, minor, patch) = mdata.captures.map { |v| v.to_i }
|
||||||
windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d')
|
if major < 2
|
||||||
Facter::Util::DotD.new(windows_facts_dot_d).create
|
# Facter 1.7 introduced external facts support directly
|
||||||
|
unless major == 1 and minor > 6
|
||||||
|
Facter::Util::DotD.new("/etc/facter/facts.d").create
|
||||||
|
Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create
|
||||||
|
|
||||||
|
# Windows has a different configuration directory that defaults to a vendor
|
||||||
|
# specific sub directory of the %COMMON_APPDATA% directory.
|
||||||
|
if Dir.const_defined? 'COMMON_APPDATA' then
|
||||||
|
windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d')
|
||||||
|
Facter::Util::DotD.new(windows_facts_dot_d).create
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
69
spec/unit/facter/pe_required_facts_spec.rb
Normal file
69
spec/unit/facter/pe_required_facts_spec.rb
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
# Puppet Enterprise requires the following facts to be set in order to operate.
|
||||||
|
# These facts are set using the file ???? and the two facts are
|
||||||
|
# `fact_stomp_port`, and `fact_stomp_server`.
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do
|
||||||
|
context "With Facter 1.6.17 which does not have external facts support" do
|
||||||
|
before :each do
|
||||||
|
Facter.stubs(:version).returns("1.6.17")
|
||||||
|
# Stub out the filesystem for stdlib
|
||||||
|
Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d").
|
||||||
|
returns(['puppet_enterprise_installer.txt'])
|
||||||
|
Dir.stubs(:entries).with("/etc/facter/facts.d").returns([])
|
||||||
|
File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt').
|
||||||
|
returns([
|
||||||
|
"fact_stomp_port=61613\n",
|
||||||
|
"fact_stomp_server=puppetmaster.acme.com\n",
|
||||||
|
"fact_is_puppetagent=true\n",
|
||||||
|
"fact_is_puppetmaster=false\n",
|
||||||
|
"fact_is_puppetca=false\n",
|
||||||
|
"fact_is_puppetconsole=false\n",
|
||||||
|
])
|
||||||
|
if Facter.collection.respond_to? :load
|
||||||
|
Facter.collection.load(:facter_dot_d)
|
||||||
|
else
|
||||||
|
Facter.collection.loader.load(:facter_dot_d)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'defines fact_stomp_port' do
|
||||||
|
Facter.fact(:fact_stomp_port).value.should == '61613'
|
||||||
|
end
|
||||||
|
it 'defines fact_stomp_server' do
|
||||||
|
Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com'
|
||||||
|
end
|
||||||
|
it 'defines fact_is_puppetagent' do
|
||||||
|
Facter.fact(:fact_is_puppetagent).value.should == 'true'
|
||||||
|
end
|
||||||
|
it 'defines fact_is_puppetmaster' do
|
||||||
|
Facter.fact(:fact_is_puppetmaster).value.should == 'false'
|
||||||
|
end
|
||||||
|
it 'defines fact_is_puppetca' do
|
||||||
|
Facter.fact(:fact_is_puppetca).value.should == 'false'
|
||||||
|
end
|
||||||
|
it 'defines fact_is_puppetconsole' do
|
||||||
|
Facter.fact(:fact_is_puppetconsole).value.should == 'false'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
[ '1.7.1', '2.0.1' ].each do |v|
|
||||||
|
context "With Facter #{v} which has external facts support" do
|
||||||
|
before :each do
|
||||||
|
Facter.stubs(:version).returns(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not call Facter::Util::DotD.new' do
|
||||||
|
Facter::Util::DotD.expects(:new).never
|
||||||
|
|
||||||
|
if Facter.collection.respond_to? :load
|
||||||
|
Facter.collection.load(:facter_dot_d)
|
||||||
|
else
|
||||||
|
Facter.collection.loader.load(:facter_dot_d)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue