Created
September 13, 2019 13:12
-
-
Save bstopp/cf925b3cce83a983427f22d1785f429f to your computer and use it in GitHub Desktop.
profile::usermgt
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
# 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