Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add apache_version fact #1347

Merged
merged 1 commit into from Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/facter/apache_version.rb
@@ -0,0 +1,8 @@
Facter.add(:apache_version) do
setcode do
if Facter::Util::Resolution.which('apachectl')
apache_version = Facter::Util::Resolution.exec('apachectl -v 2>&1')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on older versions of Debuntu, this will not work, because they renamed their apachectl to apache2ctl

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How old is 'older'? 7?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not work, but then it will just be undef so same ol' same ol'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.2, so prior ubuntu 13.x

%r{^Server version: Apache\/([\w\.]+) \(([\w]+)\)}.match(apache_version)[1]
end
end
end
20 changes: 20 additions & 0 deletions spec/unit/apache_version_spec.rb
@@ -0,0 +1,20 @@
require 'spec_helper'

describe Facter::Util::Fact do
before do
Facter.clear
end

describe 'apache_version' do
context 'with value' do
before :each do
Facter::Util::Resolution.stubs(:which).with('apachectl').returns(true)
Facter::Util::Resolution.stubs(:exec).with('apachectl -v 2>&1').returns('Server version: Apache/2.4.16 (Unix)
Server built: Jul 31 2015 15:53:26')
end
it do
expect(Facter.fact(:apache_version).value).to eq('2.4.16')
end
end
end
end