Skip to content

Instantly share code, notes, and snippets.

@kakwa
Forked from pschyska/0_pw_hash.rb
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakwa/6244f3336b8d65cdbb91 to your computer and use it in GitHub Desktop.
Save kakwa/6244f3336b8d65cdbb91 to your computer and use it in GitHub Desktop.
patched version of pw_hash.rb working with puppetserver and jruby
require 'puppet/parser/functions'
module Puppet::Parser::Functions
newfunction(:pw_hash, :type => :rvalue, :doc => "Returns the hash of a password."
) do |args|
raise Puppet::ParseError, "pw_hash takes exactly two arguments," +
"#{args.length} provided" if args.length != 2
pwd = args[0]
slt = args[1]
# walk around jruby bug on String::crypt
if RUBY_PLATFORM == "java" and "test".crypt('$1$1') != "$1$1$Bp8CU9Oujr9SSEw53WV6G."
# yum install apache-commons-codec.noarch
require '/usr/share/java/commons-codec.jar'
def pwd.crypt(salt)
org.apache.commons.codec.digest.Crypt.crypt(self.to_java_bytes, salt)
end
end
pwd.crypt("$6$#{slt}")
end
end
user { 'root':
ensure => present,
password => pw_hash($root_pw, $root_salt),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment