How to reference a user's home directory?

This seems like a simple question, but I'm trying to write a ~/.netrc file in a user's home directory, but I can't figure out how to find out where $HOME is. Assuming /home/$user is not a good idea for users like 'backup' on Ubuntu, or even /root has a different directory than everyone else.

Google tells me that this might not be so simple... what's the accepted practice to do this?

I applied some of Stephan's answer to create an array-like fact:

# Create a fact of ,user:homedir,user2:homedir2, (note leading and trailing ...

4 Answers

You are facing problems here because the desired state of your machine (presence of a netrc file in the user's homedirectory) depends on the current state of the machine (the location of the homedirectory). The only way to get the current state of the agent is through facts. So you basically have two options here:

Manage the user with puppet directly and use the home property to explicitly set the homedirectory of the specified user. In the long run this often turns out to be easier to understand and to manage.