I am trying to create a .ssh folder and then add id_rsa and known_hosts file into the .ssh folder in a windows 2016 server. This folder needs to get into any user who runs puppet manually(or as a service). To make this work I have written a custom fact $::user_profile_directory that figures the home directory (%userprofile%). The method works completely fine for all users except when puppet runs as a service.
When puppet runs as a service it creates the .ssh folder inside "c:/windows/system32/config/systemprofile" folder, but does not create the files in the created .ssh folder folder(id_rsa file known_hosts file). This does not happen if run the puppet service as any other user.
Puppet also does not show any errors in the logs and instead says the content was changed to specific md5 sum hash. But the .ssh folder does not contain any of the files if I go and check manually using the explorer.
Also if I place the files manually into the c:/windows/system32/config/systemprofile/.ssh folder it corrects the permissions on the files. I don't understand, if it's able to correct the permissions on the files if present, then why is it not able to create files. Here is my simple puppet code:
$user_home = $::user_profile_directory
file { "${user_home}/.ssh":
ensure => 'directory',
#owner => $user_name,
group => 'Administrators',
mode => '0700'
} ->
file { "${user_home}/.ssh/id_rsa":
ensure => 'file',
content => hiera('vester::vester_private_key'),
#owner => $user_name,
group => 'Administrators',
mode => '0600'
} ->
file { "${user_home}/.ssh/known_hosts":
ensure => 'file',
source => 'puppet:///modules/vester/known_hosts',
source_permissions => 'ignore',
#owner => $user_name,
#group => 'Administrators',
#mode => '0660'
}
when puppet runs as service: ${user_home} is c:/windows/system32/config/systemprofile
when puppet runs as other user (let's say vagrant): ${user_home} is c:/users/vagrant
Facter code that generates the $::user_home fact:
Facter.add('user_profile_directory') do
confine :osfamily => :windows
setcode do
ENV['USERPROFILE']
end
end
EDIT 1: Just figured, I am able to create folders but not able to create files in any of the folders/subfolders under "C:/windows/system32". How can I create files in a custom folder under system32 using puppet.?
EDIT 2: JUST figured, even though $::user_profile_directory is returning
c:/windows/system32/config/systemprofile
all my files are getting placed under
c:/windows/syswow64/config/systemprofile