Skip to content

Instantly share code, notes, and snippets.

@sveneisenschmidt
Created November 25, 2013 09:50
Show Gist options
  • Save sveneisenschmidt/7638971 to your computer and use it in GitHub Desktop.
Save sveneisenschmidt/7638971 to your computer and use it in GitHub Desktop.
Simple module approach for ceating a user on a Ubuntu host with puppet * Tested with Ubuntu 12.04 LTS. * Does not need libshadow1.8 and ruby-shadow. * Creates home folder and adds groups
# moudles/user/init.pp
class user {
exec { 'Removing existing user':
command => "deluser $user_name",
cwd => "/tmp",
path => ["/usr/bin", "/usr/sbin", "/bin"],
before => Exec["Creating user"],
onlyif => "grep -c $user_name /etc/shadow"
}
exec { 'Creating user':
command => "adduser --quiet --disabled-password $user_name && usermod -aG $user_groups $user_name",
cwd => "/tmp",
path => ["/usr/bin", "/usr/sbin", "/bin"],
}
exec { 'Setting password':
command => "openssl passwd -1 $user_password > /tmp/passwd.hash && hash=`cat /tmp/passwd.hash` && usermod -p \$hash $user_name && rm /tmp/passwd.hash",
cwd => "/tmp",
path => ["/usr/bin", "/usr/sbin", "/bin"],
subscribe => Exec["Creating user"]
}
}
$user_name = "dev"
$user_password = 'qwertzu88'
$user_groups = 'adm,sudo,ssh'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment