Skip to content

Commit

Permalink
Merge pull request puppetlabs#1878 from denzery/master
Browse files Browse the repository at this point in the history
Additional commands to detect Apache version and regexp check
  • Loading branch information
lionce authored Apr 23, 2019
2 parents 835404c + 6e73f70 commit 2d02208
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 16 additions & 3 deletions lib/facter/apache_version.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
Facter.add(:apache_version) do
confine kernel: ['FreeBSD', 'Linux']
setcode do
if Facter::Util::Resolution.which('apachectl')
apache_version = nil

if Facter::Util::Resolution.which('httpd')
apache_version = Facter::Util::Resolution.exec('httpd -V 2>&1')
Facter.debug "Matching httpd '#{apache_version}'"
elsif Facter::Util::Resolution.which('apache2')
apache_version = Facter::Util::Resolution.exec('apache2 -V 2>&1')
Facter.debug "Matching apache2 '#{apache_version}'"
elsif Facter::Util::Resolution.which('apachectl')
apache_version = Facter::Util::Resolution.exec('apachectl -v 2>&1')
Facter.debug "Matching apachectl '#{apache_version}'"
%r{^Server version: Apache/(\d+\.\d+(\.\d+)?)}.match(apache_version)[1]
elsif Facter::Util::Resolution.which('apache2ctl')
apache_version = Facter::Util::Resolution.exec('apache2ctl -v 2>&1')
Facter.debug "Matching apache2ctl '#{apache_version}'"
%r{^Server version: Apache/(\d+\.\d+(\.\d+)?)}.match(apache_version)[1]
end

unless apache_version.nil?
match = %r{^Server version: Apache\/(\d+.\d+(.\d+)?)}.match(apache_version)
unless match.nil?
match[1]
end
end
end
end
8 changes: 4 additions & 4 deletions spec/unit/apache_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
context 'with value' do
before :each do
allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux')
expect(Facter::Util::Resolution).to receive(:which).with('apachectl') { true }
expect(Facter::Util::Resolution).to receive(:exec).with('apachectl -v 2>&1') {
expect(Facter::Util::Resolution).to receive(:which).with('httpd') { true }
expect(Facter::Util::Resolution).to receive(:exec).with('httpd -V 2>&1') {
'Server version: Apache/2.4.16 (Unix)
Server built: Jul 31 2015 15:53:26'
}
Expand All @@ -24,8 +24,8 @@
context 'with value' do
before :each do
allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux')
expect(Facter::Util::Resolution).to receive(:which).with('apachectl') { true }
expect(Facter::Util::Resolution).to receive(:exec).with('apachectl -v 2>&1') {
expect(Facter::Util::Resolution).to receive(:which).with('httpd') { true }
expect(Facter::Util::Resolution).to receive(:exec).with('httpd -V 2>&1') {
'Server version: Apache/2.4.6 ()
Server built: Nov 21 2015 05:34:59'
}
Expand Down

0 comments on commit 2d02208

Please sign in to comment.