Posted by Anonymous on Sat 25th Apr 12:19
download | new post
- # returns a random but still idempotent password for a FQDN/keyword pair
- module Puppet::Parser::Functions
- newfunction(:get_id_password, :type => :rvalue) do |args|
- keyword = args[0]
- password_length = args[1].to_i
- fqdn = lookupvar("fqdn")
- # XXX: do not hardcore this path, try to figure it out from puppet.conf
- password_dir = "/var/lib/puppet/passwords"
- password_file = File.join(password_dir, keyword)
- # ensure the password directory exists
- FileUtils.mkdir_p(password_dir)
- File.chmod(0700, password_dir)
- passwords = {}
- if File.exist?(password_file)
- File.open(password_file, "r") do |file|
- passwords = Marshal.load(file.read)
- end
- end
- # create a new random password if none was found
- if not passwords.has_key?(fqdn)
- passwords[fqdn] = Array.new(password_length/2) { rand(256) }.pack('C*').unpack('H*').first
- end
- # serialize the new hash back to the database
- File.open(password_file, "w") do |file|
- file.puts(Marshal.dump(passwords))
- end
- # tell puppet we use the password file for our config
- #self.interp.newfile(password_file)
- return passwords[fqdn]
- end
- 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.
