From 3646f25af6afc011870db2370c53c8ac58a79188 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 21 Feb 2010 14:26:27 +0100 Subject: [PATCH] Rename portforwarder to portforwarder-key; Add portforwarder-user-exists fact --- facts/portforwarder.rb | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/facts/portforwarder.rb b/facts/portforwarder.rb index f7eeb91d4..0534f1ac8 100644 --- a/facts/portforwarder.rb +++ b/facts/portforwarder.rb @@ -1,14 +1,32 @@ -Facter.add("portforwarder") do - setcode do - key = nil - keyfile = '/home/portforwarder/.ssh/id_rsa.pub' - if FileTest.exist?(keyfile) - key = File.open(keyfile).read.chomp +begin + require 'etc' + + Facter.add("portforwarder-key") do + setcode do + key = nil + keyfile = '/home/portforwarder/.ssh/id_rsa.pub' + if FileTest.exist?(keyfile) + key = File.open(keyfile).read.chomp + end + key + end + end + + Facter.add("portforwarder-user-exists") do + setcode do + result = false + begin + if Etc.getpwnam('portforwarder') + result = true + end + rescue ArgumentError + end + result end - key end -end +rescue Exception => e +end # vim:set et: # vim:set ts=4: # vim:set shiftwidth=4: -- 2.20.1