Fast Recursive File Copy Recipe¶
This function can be used to work around the #1469 bug till it is fixed. I know that it is limited but it works quite well for me. Tested with Puppet 0.24.4 (current version available on Ubuntu 8.04.2)
This doesn’t work with puppet 2.6(.6,.8). Anyone know how to fix?
Store the following as a function file (e.g. /etc/puppet/modules/utilities/plugins/puppet/parser/functions/recursive_copy.rb):
require 'puppet/file_serving/configuration'
require 'puppet/file_serving/fileset'
module Puppet::Parser::Functions
newfunction(:recursive_copy, :type => :statement) do |args|
dest_path = args[0]
source = args[1]
fconfig = Puppet::FileServing::Configuration.create
fpath = fconfig.file_path(source, :node => compiler.node.name)
files = Puppet::FileServing::Fileset.new(fpath, :recurse => true).files
files.delete('.')
files.each do |rel_path|
full_path = File.join(fpath, rel_path)
stat = File.stat(full_path)
dest_file = File.join(args[0], rel_path)
src_file = File.join('puppet://', source, rel_path)
res = Puppet::Parser::Resource.new({:type => :file, :title => dest_file, :scope => self})
{:path => dest_file, :source => src_file, :owner => stat.uid, :group => stat.gid,
:mode => sprintf("%o", stat.mode)[-3..-1]}.each do |n,v|
res.set_parameter(n,v)
end
self.compiler.add_resource(self, res)
end
end
end
The you can do the following in your manifest:
node cc inherits default {
recursive_copy("/", "/private/root")
}
The first argument is the destination directory and the second argument is the mount point and directory on the puppet server. Note that you cannot choose the server! So the mount point (in the above case “private”) has to exist on the server the node is contacting! I have only one puppet master server, so this is not a problem for me.
This copies every file/directory under “/private/root” with the correct user/group/permissions to “/” on the client. The user/group/permissions are taken directly from the files on the server. So if you have a file that belongs to root with permission 700, you need to run the puppet master server as root.
Changes¶
2009-02-26
- Initial version