Created
October 20, 2013 03:38
-
-
Save scottslowe/7064759 to your computer and use it in GitHub Desktop.
This Puppet code uses define-based virtual user resources to help manage user account on systems. This includes user's SSH keys as well as other properties.
This file contains hidden or 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
define accounts::virtual ($uid,$realname,$pass,$sshkeytype,$sshkey) { | |
include accounts::params | |
# Pull in values from accounts::params | |
$homepath = $accounts::params::homepath | |
$shell = $accounts::params::shell | |
# Create the user | |
user { $title: | |
ensure => 'present', | |
uid => $uid, | |
gid => $title, | |
shell => $shell, | |
home => "${homepath}/${title}", | |
comment => $realname, | |
password => $pass, | |
managehome => true, | |
require => Group[$title], | |
} | |
# Create a matching group | |
group { $title: | |
gid => $uid, | |
} | |
# Ensure the home directory exists with the right permissions | |
file { "${homepath}/${title}": | |
ensure => directory, | |
owner => $title, | |
group => $title, | |
mode => '0750', | |
require => [ User[$title], Group[$title] ], | |
} | |
# Ensure the .ssh directory exists with the right permissions | |
file { "${homepath}/${title}/.ssh": | |
ensure => directory, | |
owner => $title, | |
group => $title, | |
mode => '0700', | |
require => File["${homepath}/${title}"], | |
} | |
# Add user's SSH key | |
if ($sshkey != '') { | |
ssh_authorized_key {$title: | |
ensure => present, | |
name => $title, | |
user => $title, | |
type => $sshkeytype, | |
key => $sshkey, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment