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