aboutsummaryrefslogtreecommitdiff
path: root/plugins/facter
diff options
context:
space:
mode:
authormh <mh@d66ca3ae-40d7-4aa7-90d4-87d79ca94279>2008-07-17 18:17:52 +0000
committermh <mh@d66ca3ae-40d7-4aa7-90d4-87d79ca94279>2008-07-17 18:17:52 +0000
commit9fc6a0baf38651d2e1673e6deb47153fe9348b75 (patch)
tree99f307de500553dda8a80cacee65a08beea50f48 /plugins/facter
parent8f006bb6a08fc95da6fa424f2c1dc746789426c5 (diff)
downloadpuppet-sshd-9fc6a0baf38651d2e1673e6deb47153fe9348b75.tar.gz
puppet-sshd-9fc6a0baf38651d2e1673e6deb47153fe9348b75.tar.bz2
added exporting and collecting of ssh keys
Taken from David Schmitts ssh module: http://git.black.co.at/?p=module-ssh git-svn-id: https://svn/ipuppet/trunk/modules/sshd@1877 d66ca3ae-40d7-4aa7-90d4-87d79ca94279
Diffstat (limited to 'plugins/facter')
-rw-r--r--plugins/facter/sshkeys.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/plugins/facter/sshkeys.rb b/plugins/facter/sshkeys.rb
new file mode 100644
index 0000000..abf838c
--- /dev/null
+++ b/plugins/facter/sshkeys.rb
@@ -0,0 +1,44 @@
+["/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)
+ regex = %r{^(\S+) (\S+) (\S+)$}
+ begin
+ line = File.open(filepath).read.chomp
+ if match = regex.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