From 4d96b30960a5287d55f2df86eb366945efc10c7b Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Sun, 18 Mar 2012 20:24:46 +0000 Subject: [PATCH] booleans, again Signed-off-by: Stephen Gran --- modules/debian-org/lib/facter/hosts.rb | 6 +- modules/debian-org/lib/facter/ipaddresses.rb | 72 ++++++------ modules/debian-org/lib/facter/mta.rb | 9 +- .../debian-org/lib/facter/portforwarder.rb | 2 +- modules/debian-org/lib/facter/raidarray.rb | 28 ++++- modules/debian-org/lib/facter/servertype.rb | 3 +- modules/debian-org/lib/facter/services.rb | 2 +- modules/debian-org/lib/facter/software.rb | 105 ++++++++++++++---- 8 files changed, 159 insertions(+), 68 deletions(-) diff --git a/modules/debian-org/lib/facter/hosts.rb b/modules/debian-org/lib/facter/hosts.rb index 2a6b692a2..63c04cb27 100644 --- a/modules/debian-org/lib/facter/hosts.rb +++ b/modules/debian-org/lib/facter/hosts.rb @@ -11,7 +11,11 @@ Facter.add("brokenhosts") do end end setcode do - brokenhosts + if brokenhosts + true + else + '' + end end end diff --git a/modules/debian-org/lib/facter/ipaddresses.rb b/modules/debian-org/lib/facter/ipaddresses.rb index 05e3e9097..80b59bd35 100644 --- a/modules/debian-org/lib/facter/ipaddresses.rb +++ b/modules/debian-org/lib/facter/ipaddresses.rb @@ -1,22 +1,22 @@ Facter.add("v4ips") do - confine :kernel => :linux - addrs = [] - if FileTest.exist?("/bin/ip") - %x{ip addr list}.each do |line| - next unless line =~ /\s+inet/ - next if line =~ /scope (link|host)/ - if line =~ /\s+inet\s+(\S+)\/\d{1,2} .*/ - addrs << $1 - end - end - end - ret = addrs.join(",") - if ret.empty? - ret = 'no' - end - setcode do - ret - end + confine :kernel => :linux + addrs = [] + if FileTest.exist?("/bin/ip") + %x{ip addr list}.each do |line| + next unless line =~ /\s+inet/ + next if line =~ /scope (link|host)/ + if line =~ /\s+inet\s+(\S+)\/\d{1,2} .*/ + addrs << $1 + end + end + end + ret = addrs.join(",") + if ret.empty? + ret = 'no' + end + setcode do + ret + end end Facter.add("v4ips") do @@ -44,23 +44,23 @@ Facter.add("v4ips") do end Facter.add("v6ips") do - confine :kernel => :linux - addrs = [] - if FileTest.exist?("/bin/ip") - %x{ip addr list}.each do |line| - next unless line =~ /\s+inet/ - next if line =~ /scope (link|host)/ - if line =~ /\s+inet6\s+(\S+)\/\d{1,3} .*/ - addrs << $1 - end - end - end - ret = addrs.join(",") - if ret.empty? - ret = 'no' - end - setcode do - ret - end + confine :kernel => :linux + addrs = [] + if FileTest.exist?("/bin/ip") + %x{ip addr list}.each do |line| + next unless line =~ /\s+inet/ + next if line =~ /scope (link|host)/ + if line =~ /\s+inet6\s+(\S+)\/\d{1,3} .*/ + addrs << $1 + end + end + end + ret = addrs.join(",") + if ret.empty? + ret = 'no' + end + setcode do + ret + end end diff --git a/modules/debian-org/lib/facter/mta.rb b/modules/debian-org/lib/facter/mta.rb index 98ed4338c..9b612609f 100644 --- a/modules/debian-org/lib/facter/mta.rb +++ b/modules/debian-org/lib/facter/mta.rb @@ -9,11 +9,16 @@ Facter.add("mta") do end Facter.add("exim_ssl_certs") do - setcode do - FileTest.exist?("/etc/exim4/ssl/") && + certs = FileTest.exist?("/etc/exim4/ssl/") && FileTest.exist?("/etc/exim4/ssl/ca.crl") && FileTest.exist?("/etc/exim4/ssl/thishost.crt") && FileTest.exist?("/etc/exim4/ssl/ca.crt") && FileTest.exist?("/etc/exim4/ssl/thishost.key") + setcode do + if certs + true + else + '' + end end end diff --git a/modules/debian-org/lib/facter/portforwarder.rb b/modules/debian-org/lib/facter/portforwarder.rb index fe3cebdec..67888aa77 100644 --- a/modules/debian-org/lib/facter/portforwarder.rb +++ b/modules/debian-org/lib/facter/portforwarder.rb @@ -14,7 +14,7 @@ begin Facter.add("portforwarder_user_exists") do setcode do - result = false + result = '' begin if Etc.getpwnam('portforwarder') result = true diff --git a/modules/debian-org/lib/facter/raidarray.rb b/modules/debian-org/lib/facter/raidarray.rb index d7735329e..d0d130929 100644 --- a/modules/debian-org/lib/facter/raidarray.rb +++ b/modules/debian-org/lib/facter/raidarray.rb @@ -1,14 +1,18 @@ Facter.add("smartarraycontroller") do confine :kernel => :linux setcode do - FileTest.exist?("/dev/cciss/") + if FileTest.exist?("/dev/cciss/") + true + else + '' + end end end Facter.add("ThreeWarecontroller") do confine :kernel => :linux setcode do - is3w = false + is3w = '' if FileTest.exist?("/proc/scsi/scsi") IO.foreach("/proc/scsi/scsi") { |x| is3w = true if x =~ /Vendor: 3ware/ @@ -21,28 +25,40 @@ end Facter.add("megaraid") do confine :kernel => :linux setcode do - FileTest.exist?("/dev/megadev0") + if FileTest.exist?("/dev/megadev0") + true + else + '' + end end end Facter.add("mptraid") do confine :kernel => :linux setcode do - FileTest.exist?("/dev/mptctl") or FileTest.exist?("/dev/mpt0") or FileTest.exist?("/proc/mpt/summary") + if FileTest.exist?("/dev/mptctl") or FileTest.exist?("/dev/mpt0") or FileTest.exist?("/proc/mpt/summary") + true + else + '' + end end end Facter.add("aacraid") do confine :kernel => :linux setcode do - FileTest.exist?("/dev/aac0") + if FileTest.exist?("/dev/aac0") + true + else + '' + end end end Facter.add("swraid") do confine :kernel => :linux setcode do - swraid = false + swraid = '' if FileTest.exist?("/proc/mdstat") && FileTest.exist?("/sbin/mdadm") IO.foreach("/proc/mdstat") { |x| swraid = true if x =~ /md[0-9]+ : active/ diff --git a/modules/debian-org/lib/facter/servertype.rb b/modules/debian-org/lib/facter/servertype.rb index e261e709a..85970c168 100644 --- a/modules/debian-org/lib/facter/servertype.rb +++ b/modules/debian-org/lib/facter/servertype.rb @@ -1,9 +1,8 @@ Facter.add("kvmdomain") do setcode do + result = '' if File.new('/proc/cpuinfo').read().index('QEMU Virtual CPU') result = true - else - result = false end result end diff --git a/modules/debian-org/lib/facter/services.rb b/modules/debian-org/lib/facter/services.rb index 8ad284719..097116204 100644 --- a/modules/debian-org/lib/facter/services.rb +++ b/modules/debian-org/lib/facter/services.rb @@ -2,7 +2,7 @@ Facter.add(service + "_host") do confine :kernel => :linux service_name = "#{service}." + Facter.domain - active = false + active = '' setcode do if FileTest.exist?("/usr/bin/dig") diff --git a/modules/debian-org/lib/facter/software.rb b/modules/debian-org/lib/facter/software.rb index 598d7a194..5c60dd4eb 100644 --- a/modules/debian-org/lib/facter/software.rb +++ b/modules/debian-org/lib/facter/software.rb @@ -1,46 +1,82 @@ Facter.add("apache2") do setcode do - FileTest.exist?("/usr/sbin/apache2") + if FileTest.exist?("/usr/sbin/apache2") + true + else + '' + end end end Facter.add("clamd") do setcode do - FileTest.exist?("/usr/sbin/clamd") + if FileTest.exist?("/usr/sbin/clamd") + true + else + '' + end end end Facter.add("exim4") do setcode do - FileTest.exist?("/usr/sbin/exim4") + if FileTest.exist?("/usr/sbin/exim4") + true + else + '' + end end end Facter.add("postfix") do setcode do - FileTest.exist?("/usr/sbin/postfix") + if FileTest.exist?("/usr/sbin/postfix") + true + else + '' + end end end Facter.add("postgres81") do setcode do - FileTest.exist?("/usr/lib/postgresql/8.1/bin/postgres") + if FileTest.exist?("/usr/lib/postgresql/8.1/bin/postgres") + true + else + '' + end end end Facter.add("postgres83") do setcode do - FileTest.exist?("/usr/lib/postgresql/8.3/bin/postgres") + if FileTest.exist?("/usr/lib/postgresql/8.3/bin/postgres") + true + else + '' + end end end Facter.add("postgres84") do setcode do - FileTest.exist?("/usr/lib/postgresql/8.4/bin/postgres") + if FileTest.exist?("/usr/lib/postgresql/8.4/bin/postgres") + true + else + '' + end end end Facter.add("postgres90") do setcode do - FileTest.exist?("/usr/lib/postgresql/9.0/bin/postgres") + if FileTest.exist?("/usr/lib/postgresql/9.0/bin/postgres") + true + else + '' + end end end Facter.add("postgrey") do setcode do - FileTest.exist?("/usr/sbin/postgrey") + if FileTest.exist?("/usr/sbin/postgrey") + true + else + '' + end end end Facter.add("greylistd") do @@ -50,31 +86,53 @@ Facter.add("greylistd") do end Facter.add("policydweight") do setcode do - FileTest.exist?("/usr/sbin/policyd-weight") + if FileTest.exist?("/usr/sbin/policyd-weight") + true + else + '' + end end end Facter.add("vsftpd") do setcode do - FileTest.exist?("/usr/sbin/vsftpd") + if FileTest.exist?("/usr/sbin/vsftpd") + true + else + '' + end end end Facter.add("spamd") do setcode do - FileTest.exist?("/usr/sbin/spamd") + if FileTest.exist?("/usr/sbin/spamd") + true + else + '' + end end end Facter.add("php5") do - setcode do - FileTest.exist?("/usr/lib/apache2/modules/libphp5.so") or + php = FileTest.exist?("/usr/lib/apache2/modules/libphp5.so") or FileTest.exist?("/usr/bin/php5") or FileTest.exist?("/usr/bin/php5-cgi") or FileTest.exist?("/usr/lib/cgi-bin/php5") + setcode do + if php + true + else + '' + end end end Facter.add("php5suhosin") do - setcode do - FileTest.exist?("/usr/lib/php5/20060613/suhosin.so") or + suhosin=FileTest.exist?("/usr/lib/php5/20060613/suhosin.so") or FileTest.exist?("/usr/lib/php5/20060613+lfs/suhosin.so") + setcode do + if suhosin + true + else + '' + end end end Facter.add("syslogversion") do @@ -84,12 +142,21 @@ Facter.add("syslogversion") do end Facter.add("rsyncd") do setcode do - FileTest.exist?("/etc/rsyncd.conf") + if FileTest.exist?("/etc/rsyncd.conf") + true + else + '' + end end end Facter.add("unbound") do - setcode do - FileTest.exist?("/usr/sbin/unbound") and + unbound=FileTest.exist?("/usr/sbin/unbound") and FileTest.exist?("/var/lib/unbound/root.key") + setcode do + if unbound + true + else + '' + end end end -- 2.20.1