Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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]}")
user { 'root':
ensure => present,
password => pw_hash($root_pw, $root_salt),
Copy link

DanyHenriquez commented Mar 13, 2015

Thanks. This helped me out a lot!

Copy link

iakovgan commented Apr 24, 2015

I will just leave here an inline_template version

        ensure     => present,
        password   => inline_template("<%= '$pass'.crypt('\$6$$salt') %>"),

Copy link

vikas027 commented Oct 16, 2015

Nice pschyska, works like a charm.

Copy link

prathyushmr commented Nov 1, 2015

Nice one

Copy link

william-richard commented Mar 13, 2016

If you use stdlib, it includes a function that does this now:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment