From 8c71b33d54a89331e295a0c586dad49523de9c95 Mon Sep 17 00:00:00 2001 From: Pall Valmundsson Date: Sun, 29 Mar 2015 23:53:03 +0000 Subject: [PATCH] The version fact currently supplies the available redis version regardless of whether it's installed or not. The result is that all nodes contain a fact that implies that the latest available redis version seems to be installed. This change switches from using yum to rpm to query the locally installed package database. It has the added benefit of not querying yum, which can be costly. Addresses #39 in part. --- lib/facter/redis_version.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/facter/redis_version.rb b/lib/facter/redis_version.rb index 1aa7606..28991ee 100644 --- a/lib/facter/redis_version.rb +++ b/lib/facter/redis_version.rb @@ -40,14 +40,14 @@ setcode do - yum = `which yum 2> /dev/null`.chomp - if yum == '' - yum = '/usr/bin/yum' + rpm = `which rpm 2> /dev/null`.chomp + if rpm == '' + rpm = '/usr/bin/rpm' end redis_version = Facter::Util::Resolution.exec('/usr/sbin/redis-server --version') if redis_version.nil? - redis_version = Facter::Util::Resolution.exec(yum+" info redis 2> /dev/null | /bin/grep '^Version' | /bin/awk -F ':' '{printf(\"%s\",$2)}' | sort -nr | head -1") + redis_version = Facter::Util::Resolution.exec(rpm+" -q --queryformat '%{version}\\n' redis | grep -v 'not installed' | sort -nr | head -1") end case redis_version @@ -64,7 +64,7 @@ #set version to 2.2 redis_version = '2.2.x' else - redis_version = 'nil' + redis_version = nil end redis_version end