Use Puppet to deploy files to all user’s home directory

deploymentpuppetuser-management

I want to deploy a simple text file (a git commit message template) to each user's home directory using Puppet.

I came across this post which seems very close, but the part I'm not clear on is how do I generate a list of users for each node?

In the post they hardcode the users like this:

 applink::desktoplinks { [ "user1", "user2", "user3" ]: }

I can't hard-code the list because these are developer machines and might have a variety of different users that are specific to each node.

Looking at this post, I think I need to use virtual resources, but being a total newbie, just by reading the docs and the provided samples I can't quite seem to figure it out.

Can somebody point me to a quick sample or recipe somewhere that illustrates how to do this?

Best Answer

To generate a list of users you need to create a new fact. Any information that comes from the host that will be configured needs to be a fact.

For example, the following fact returns the whole /etc/passwd:

# etcpasswd.rb

Facter.add("etcpasswd") do
        setcode do
                File.read('/etc/passwd')
        end
end

You put this fact on the lib/facter subdirectory of a module, or under plugins/facter in Puppet's base directory. I think you need pluginsync = true in puppet.conf too, but that might be only for older Puppet versions.

You can see an example of this at work on my puppet users module.

Related Topic