Skip to content

Instantly share code, notes, and snippets.

@JonTheNiceGuy
Created December 12, 2015 21:57
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 JonTheNiceGuy/1bb411bb415c7d05c2b2 to your computer and use it in GitHub Desktop.
Save JonTheNiceGuy/1bb411bb415c7d05c2b2 to your computer and use it in GitHub Desktop.
Want to set a username and password in Puppet? Keep getting "You reset the password for a user 8m times" in your logs? This may be the gist for you! Only really works if you've got a consistent user salt across all your boxes :)
define createuser (
$username = $title,
$password = 'defaultpw',
$groups = ['users'],
$home = "/home/${username}"
$shell = '/bin/bash') {
user { $username:
ensure => present,
password => generate(
'/bin/sh',
'-c',
"mkpasswd -m sha-512 ${password} \$(</etc/shadow awk -v user=${username} -F : 'user == \$1 {print \$2}' | cut -d '$' -f 3) | tr -d '\n'"
),
home => $home,
groups => $groups,
shell => $shell,
managehome => yes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment