Skip to content

Instantly share code, notes, and snippets.

@scottslowe
Created October 20, 2013 03:38
Show Gist options
  • Save scottslowe/7064759 to your computer and use it in GitHub Desktop.
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.
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