Skip to content

Instantly share code, notes, and snippets.

@tawateer
Forked from pschyska/0_pw_hash.rb
Created December 14, 2016 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tawateer/36968f034ed90c077f488326d200ba50 to your computer and use it in GitHub Desktop.
Save tawateer/36968f034ed90c077f488326d200ba50 to your computer and use it in GitHub Desktop.
PW hashing with puppet parser function
# lib/puppet/parser/functions/pw_hash.rb
module Puppet::Parser::Functions
newfunction(:pw_hash, type: :rvalue) do |args|
raise Puppet::ParseError, "pw_hash takes exactly two arguments, #{args.length} provided" if args.length != 2
# SHA512 ($6), default number of rounds (5000)
# rounds could be specified by prepending rounds=<n>$ parameter before the salt, i.e.
# args[0].crypt("$6$rounds=50000$#{args[1]}")
args[0].crypt("$6$#{args[1]}")
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