Created
November 25, 2013 09:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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