Here we go:
Part 1: Custom Fact (modules/users/lib/facter/user_home.rb)
require 'etc'
Etc.passwd { |user|
Facter.add("home_#{user.name}") do
setcode do
user.dir
end
end
}
When you are creating a user, you have access to the homedir. I use a define that has default parameters of
$userhome = "/home/${title}", $username = $title,You can override the userhome value. The combination of resources I found to work is as follows:
exec { "mkdir-${username}": command => "/bin/mkdir -p ${homedirdir}", unless => "test -d ${homedirdir}", } file { $userhome: ensure => directory, require => [ User[$username], Exec["mkdir-${username}"], ] } file { "${userhome}/.ssh": ensure => directory, require => User[$username], } file { "${userhome}/.ssh/authorized_keys": ensure => present, require => File["${userhome}/.ssh"], } ssh_authorized_key { "${username}_rsa_key": ensure => $ensure, user => $username, key => ".....", type => 'ssh-rsa', }Now, for putting keys in other user homedirs - like a role account for restricted ssh - using only the role account login and the user account login,
$home_fact = "home_${role_account_login}" $homedir = inline_template("<%= scope.lookupvar('::${home_fact}') %>") User[$role_account_login]->
File [ "${homedir}/.ssh/authorized_keys"] ->
ssh_authorized_key { "${user_account_login}_rsa_key_for_${role_account_login}": ensure => $ensure, key => "....", type => 'ssh-rsa', user => $role_account_login, }The chaining was discovered thru some long and painful trial and error.
Also, there is the matter of the "options" parameter for ssh_authorized_key, but I did not want to complicate this too much.
This should get you moving forward.