I need to create a test user with a password using puppet.
I\'ve read that puppet cannot manage user passwords in a generic cross-platform way, which is a pity. I am
I came up with a method that doesn't need anything to add if you have python 2.6. I tested this on puppet 3.6.2 on CentOS 6.4:
$pass="password"
$shatag="\$6\$"
$cmd="import crypt, base64, os, sys; sys.stdout.write(crypt.crypt('$pass', '$shatag' + base64.b64encode(os.urandom(16))[:8]))"
user { 'boop':
ensure => present,
password => generate ("/usr/bin/python", "-c", $cmd),
}
the sha tag is here to specify to crypt the hash method we want:
6 is the type of hash for SHA-512
thx davey and wiki_crypt
sys.stdout.write is here to avoid '\n' of print
base64.b64encode(os.urandom(16))[:8]):
os.urandom(16) create a 16 bits long binary stringbase64.b64encode encode this string in base64[:8] take the first 8 characters of this string (as base64 encoding length may vary)generate is a puppet function that create text when on the puppet master.
You can't use this function like you want because it is 'protected' ê.é (last post suggest a workaround to this protection-or-whatever)
hth