dir = "/root/.ssh"

{"root_sshdsakey" => "id_dsa.pub", "root_sshrsakey" => "id_rsa.pub"}.each do |name,file|
  Facter.add(name) do
    setcode do
      value = nil
      filepath = File.join(dir,file)
      if FileTest.file?(filepath)
        begin
          File.open(filepath) { |f| value = f.read.chomp.split(/\s+/)[1] }
        rescue
          value = nil
        end
      end
      value
    end
  end
end
