From 057779d73208a09173dfa740b6888d85e5d17041 Mon Sep 17 00:00:00 2001 From: Pall Valmundsson Date: Mon, 30 Mar 2015 00:10:37 +0000 Subject: [PATCH] This adds a simple redis_port fact that checks the port configuration in redis.conf as specified in the params module for each platform. --- lib/facter/redis_port.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/facter/redis_port.rb diff --git a/lib/facter/redis_port.rb b/lib/facter/redis_port.rb new file mode 100644 index 0000000..39418f1 --- /dev/null +++ b/lib/facter/redis_port.rb @@ -0,0 +1,31 @@ +require 'facter' + +Facter.add("redis_port", :timeout => 120) do + confine :osfamily => "Debian" + + setcode do + redis_port = nil + if File.exists?("/etc/redis/redis.conf") + redis_port_grep = Facter::Util::Resolution.exec("grep '^port' /etc/redis/redis.conf | awk '{print $2}'") + if redis_port_grep =~ /^\d+$/ + redis_port = redis_port_grep + end + end + redis_port + end +end + +Facter.add("redis_port", :timeout => 120) do + confine :osfamily => "RedHat" + + setcode do + redis_port = nil + if File.exists?("/etc/redis.conf") + redis_port_grep = Facter::Util::Resolution.exec("grep '^port' /etc/redis.conf | awk '{print $2}'") + if redis_port_grep =~ /^\d+$/ + redis_port = redis_port_grep + end + end + redis_port + end +end