Linux-VServer pastebin service

Posted by Anonymous on Sat 25th Apr 12:19
download | new post

  1. # returns a random but still idempotent password for a FQDN/keyword pair  
  2. module Puppet::Parser::Functions  
  3.     newfunction(:get_id_password, :type => :rvalue) do |args|  
  4.         keyword = args[0]  
  5.         password_length = args[1].to_i  
  6.         fqdn = lookupvar("fqdn")  
  7.  
  8.         # XXX: do not hardcore this path, try to figure it out from puppet.conf  
  9.         password_dir = "/var/lib/puppet/passwords"  
  10.         password_file = File.join(password_dir, keyword)  
  11.  
  12.         # ensure the password directory exists  
  13.         FileUtils.mkdir_p(password_dir)  
  14.         File.chmod(0700, password_dir)  
  15.  
  16.         passwords = {}  
  17.  
  18.         if File.exist?(password_file)  
  19.             File.open(password_file, "r") do |file|  
  20.                 passwords = Marshal.load(file.read)  
  21.             end  
  22.         end  
  23.  
  24.         # create a new random password if none was found  
  25.         if not passwords.has_key?(fqdn)  
  26.             passwords[fqdn] = Array.new(password_length/2) { rand(256) }.pack('C*').unpack('H*').first  
  27.         end  
  28.  
  29.         # serialize the new hash back to the database  
  30.         File.open(password_file, "w") do |file|  
  31.             file.puts(Marshal.dump(passwords))  
  32.         end  
  33.  
  34.         # tell puppet we use the password file for our config  
  35.         #self.interp.newfile(password_file)  
  36.  
  37.         return passwords[fqdn]  
  38.     end  
  39. end 

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
Your Name

Remember my name in a cookie