Skip to content

Instantly share code, notes, and snippets.

@gutocarvalho
Created November 18, 2015 01:48
Show Gist options
  • Save gutocarvalho/d60987f4cee423d017c4 to your computer and use it in GitHub Desktop.
Save gutocarvalho/d60987f4cee423d017c4 to your computer and use it in GitHub Desktop.
Facter.add(:postgresql) do
setcode do
confine :kernel => 'Linux'
postgresql = {}
distid = Facter.value(:osfamily)
case distid
when /RedHat|Suse/
postgresql_check = Facter::Core::Execution.exec('which postmaster')
when "Debian"
postgresql_check = Facter::Core::Execution.exec('dpkg --list|awk \'{ print $1, $2 }\'|grep ^"ii postgresql"$')
end
if postgresql_check == ""
postgresql_installed = false
else
postgresql_installed = true
end
if postgresql_installed
distid = Facter.value(:osfamily)
case distid
when /RedHat|Suse/
postgresql_version = Facter::Core::Execution.exec('rpm -q --queryformat "%{VERSION}" postgresql-server')
when "Debian"
postgresql_version = Facter::Core::Execution.exec('dpkg-query -W -f=\'${Version}\' postgresql')
else
postgresql_version = 'Unknown'
end
end
postgresql[:installed] = postgresql_installed
postgresql[:version] = postgresql_version
postgresql
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment