-
Notifications
You must be signed in to change notification settings - Fork 614
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 a fact for installed postgres version #1609
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
Facter.add('postgres_version') do | ||
confine { Facter::Core::Execution.which('postgres') } | ||
setcode do | ||
version = Facter::Core::Execution.execute('postgres -V 2>/dev/null') | ||
version.match(%r{\d+\.\d+$})[0] if version | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex won't match the output of Debian family packages: kenyon@lithium ~ % /usr/lib/postgresql/14/bin/postgres -V
postgres (PostgreSQL) 14.13 (Debian 14.13-1.pgdg110+1) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. Guess the regex will have to be adjusted. This is RHEL 9 by the way, and I believe also vanilla PostgreSQL:
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
describe Facter::Util::Fact.to_s do | ||
before(:each) do | ||
Facter.clear | ||
end | ||
|
||
describe 'postgres_version' do | ||
context 'with value' do | ||
before :each do | ||
allow(Facter::Core::Execution).to receive(:which).and_return('/usr/bin/postgres') | ||
allow(Facter::Core::Execution).to receive(:execute).with('postgres -V 2>/dev/null').and_return('postgres (PostgreSQL) 10.0') | ||
end | ||
|
||
it 'postgres_version' do | ||
expect(Facter.fact(:postgres_version).value).to eq('10.0') | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least on Debian family,
postgres
is not inPATH
, so this wouldn't work. Maybe it'd be better to get the version frompsql
, which is in thePATH
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with that is that
psql
might be a different version, and I would like to ensure that it's actually the database server version that gets reported. I guess this needs a bit more thought.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated below, perhaps
pg_config --version
could be used.