1
0
Fork 0
puppet-random_password/lib/puppet/parser/functions/random_password.rb

19 lines
395 B
Ruby

require 'securerandom'
module Puppet::Parser::Functions
newfunction(:random_password, :type => :rvalue) do |args|
length = args[0] - 1
store = args[1]
if(args.length != 2)
raise Puppet::ParsError, 'Usage: random_password(length, store)'
end
password = SecureRandom.hex[0..length]
File.open(store, 'w') { |f| f.write(password) }
return password
end
end