I'm starting to use puppet to manage a couple of servers and I'm not sure how to achieve the following.
I've got a users
module which I use to create common users across all servers. I've got a git
module which I use to install git and set up a system-wide config in /etc/gitconfig
. What I'd like to do is:
- On servers which are configured to install git (not all of them), go and drop a (templated)
.gitconfig
into the home directories of all existing users. And obviously manage this for changes to the template. - Add the
.gitconfig
for all future users. But I don't feel this belongs in theusers
module - I think it belongs in thegit
module. It feels like I want to know when any user has been added (not just a given instance of user), and then be able to access the parameters of that user creation (e.g. home directory, real name and username).
Essentially, part 2 would be easy if I just deployed a templated .gitconfig
to all users created by the users
module. But I don't really want users to have a .gitconfig
file if git isn't installed on the system. So what I'm really trying to say is "for all managed users on this system, if git is installed, manage a .gitconfig
file".
Thanks!
Yo will need to use two procedures , first for already created accounts :
http://www.cyberciti.biz/tips/linux-unix-shell-batch-copy.html
and another one for future users :
http://linuxers.org/howto/how-set-default-content-new-users-home-directory-using-etcskel
It'll be easier if users and nodes that need to have git are managed by puppet:
Then for each git node, include class git.
So you either have to define this on the users module, or export a virtual resource from it. Given the usage, I don't see a way to do it with virtual resources.
Strictly speaking, create a custom fact to check if it is installed. For example:
On the other hand, the
git
module could export a virtual resource, such as the.gitconfig
file, and the user module could realize it. I don't think it is possible to realize the same resource in a parameterized (user's home directory) way.Well, that you know how to do.
If you want to just ensure a base file, use tags. The virtual file resource will only get realized if the git class has been included. You could set this up with a template to add in the user name and email. This can cause problems if users want to customize their git config though (puppet will overwrite their changes).
You may also be able to leverage the puppet-stdlib (https://forge.puppetlabs.com/puppetlabs/stdlib) getparam feature.
Untested code, not sure if this would work. Generally I like the tagged virtual resources a lot.