summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormh <mh@immerda.ch>2009-10-31 15:16:27 +0100
committerMicah Anderson <micah@riseup.net>2009-12-07 16:04:29 -0500
commit81063ee57bdbdc1e888755ed74af795dfbcac611 (patch)
tree1731412eb50c00e19d89a077dbf0ae48afa911c9 /lib
parent384b1466ea7b860f7f17b05281c49fa5a8ebe42a (diff)
move plugin directory to fit new 0.25 style
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/sshkeys.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/facter/sshkeys.rb b/lib/facter/sshkeys.rb
new file mode 100644
index 0000000..0e94a03
--- /dev/null
+++ b/lib/facter/sshkeys.rb
@@ -0,0 +1,45 @@
+["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each { |dir|
+ {"SSHDSAKey_key" => "ssh_host_dsa_key.pub",
+ "SSHRSAKey_key" => "ssh_host_rsa_key.pub"}.each { |name,file|
+ Facter.add(name ) do
+ setcode do
+ value = nil
+ filepath = File.join(dir,file)
+ if FileTest.file?(filepath)
+ regex1 = %r{^(\S+) (\S+) (\S+)$}
+ regex2 = %r{^(\S+) (\S+)(\s+)$}
+ begin
+ line = File.open(filepath).read.chomp
+ if (match = regex1.match(line)) or (match = regex2.match(line))
+ value = match[2]
+ end
+ rescue
+ value = nil
+ end
+ end
+ value
+ end # end of proc
+ end # end of add
+ } # end of hash each
+ {"SSHDSAKey_comment" => "ssh_host_dsa_key.pub",
+ "SSHRSAKey_comment" => "ssh_host_rsa_key.pub"}.each { |name,file|
+ Facter.add(name ) do
+ setcode do
+ value = nil
+ filepath = File.join(dir,file)
+ if FileTest.file?(filepath)
+ regex = %r{^(\S+) (\S+) (\S+)$}
+ begin
+ line = File.open(filepath).read.chomp
+ if match = regex.match(line)
+ value = match[3]
+ end
+ rescue
+ value = nil
+ end
+ end
+ value
+ end # end of proc
+ end # end of add
+ } # end of hash each
+} # end of dir each