I know that Facter is not intended to do this, but I would be glad to know how to write a custom fact to copy files from Puppet clients to main Puppet server. Thank you.
2 Answers
Copying files as a fact? Why would you want to do that? You can simply have an Exec
to scp
or ftp
the file elsewhere.
If you need to check the contents of a file for a fact, take this as an example:
# etcgroup.rb
Facter.add("etcgroup") do
setcode do
File.read('/etc/group')
end
end
You can then use regex functions to extract information from inside it. Note that this is sent as part of the URL of a GET request, which is usually limited in number of characters. I have LimitRequestLine 30000
in my apache2.conf
for just such a reason.
If you really, truly need to copy the file, you can do something like this:
# etcgroup.rb
Facter.add("etcgroup") do
setcode do
%{ scp -i /path/to/identity /etc/group user@puppet:/path && echo ok || echo not ok}.chomp
end
end
It will send the file by scp
, using an identity to avoid passing passwords, and then return either ok
or not ok
as fact.
I think a better way would be to use auditing with a remote filebucket (I believe you need 2.6.5+ for this).
Something like:
filebucket { "server":
server => "your.puppet.server";
}
file { "/etc/group":
audit => content;
backup => server;
}
This causes /etc/group to be uploaded to the server when (a) it changes or (b) it hasn't been seen before. Then, on the server you can use the 'puppet filebucket' utility to check out the data the clients sent. This is way better than putting it in a fact.