diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/sshkeys.rb | 45 | ||||
-rw-r--r-- | lib/puppet/parser/functions/ssh_keygen.rb | 5 |
2 files changed, 4 insertions, 46 deletions
diff --git a/lib/facter/sshkeys.rb b/lib/facter/sshkeys.rb deleted file mode 100644 index 0e94a03..0000000 --- a/lib/facter/sshkeys.rb +++ /dev/null @@ -1,45 +0,0 @@ -["/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 diff --git a/lib/puppet/parser/functions/ssh_keygen.rb b/lib/puppet/parser/functions/ssh_keygen.rb index 09b3d3b..597315e 100644 --- a/lib/puppet/parser/functions/ssh_keygen.rb +++ b/lib/puppet/parser/functions/ssh_keygen.rb @@ -14,7 +14,10 @@ Puppet::Parser::Functions::newfunction(:ssh_keygen, :type => :rvalue, :doc => end dir = File.dirname(private_key_path) - Puppet::Util.recmkdir(dir,0700) unless File.directory?(dir) + unless File.directory?(dir) + require 'fileutils' + FileUtils.mkdir_p(dir, :mode => 0700) + end unless [private_key_path,public_key_path].all?{|path| File.exists?(path) } output = Puppet::Util.execute(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', private_key_path, '-P', '', '-q']) raise Puppet::ParseError, "Something went wrong during key generation! Output: #{output}" unless output.empty? |