Skip to content

Instantly share code, notes, and snippets.

@bstopp
Created September 13, 2019 13:12
Show Gist options
  • Save bstopp/cf925b3cce83a983427f22d1785f429f to your computer and use it in GitHub Desktop.
Save bstopp/cf925b3cce83a983427f22d1785f429f to your computer and use it in GitHub Desktop.
profile::usermgt
# User Management profile
#
# Creates users defined from hiera. Also manages any SSH Authorized Keys for those users.
#
# Standardizes some configurations for user's home.
#
# Users must exist to specify an SSH key.
#
class profile::usermgt {
lookup('profile::usermgt::users', Hash, 'deep', {}).each | $resource_title, $params| {
if $params['name'] {
$home = $params['name']
} else {
$home = $resource_title
}
user {
# Give the defaults so you do not have to set these the same for
# every user in your hiera data
default:
ensure => 'present',
home => "/home/${resource_title}",
managehome => true
;
# Set all parameters from values in the hash
# (The '* =>' construct "splats" everything in the $params hash)
#
$resource_title: * => $params;
}
}
lookup('profile::usermgt::ssh_authorized_keys', Hash, 'deep', {}).each | $resource_title, $attributes| {
Resource['ssh_authorized_key'] {
$resource_title: * => $attributes
}
}
User<| |>
-> Ssh_authorized_key<| |>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment