ansible/ansible — pull request #1809 by smoothify (2012-12-31 14:53:23+00:00)
Title: Add rcopy module to handle recursive copying.

[Here is the squashed commit version of https://github.com/ansible/ansible/pull/1808]

I needed to have a recursive copy function to help keep track of folders of multiple files, rather than specifiying them individually.

I thought about modifying the copy module to add a recursive parameter, but to avoid introducing unforeseen problems with copy, I cloned it into a new rcopy module for now.

It works exactly the same as copy except it allows directories to be passed in as the src parameter. It recurses through the list of files contained within them and then runs the copy process for each file individually.

I have created both an action_plugin, and a module. The module is unchanged from copy, with the exception of a call to os.makedirs(dest) if the dest parent folder does not exist.

It mimics rsync behaviour with the traling slashes on src:

# A trailing / on a source name means "copy the contents of this directory".
# Without a trailing slash it means "copy the directory".
# Trailing slashes on destinations make no difference.

There is also an exclude file mask applied, for which i've added a value to constants.py. This is a comma separated list of filename paths that should be excluded from the upload - typically hidden files like .DS_Store, Thumbs.db, VCS files, etc.

rcopy_exclude=.DS_Store,Desktop.ini,._*,Thumbs.db,.git,.git*,.svn

Some more notes

Because it uses the same basic functionality as copy, it does check the md5sum for each file, and won't upload if it hasn't changed.

It is also non destructive if a file gets removed from src, it won't clean up those files if they are no longer in src, and it won't affect any files already in one of directories on the destination.

There is currently no recursion limit, so it will, i believe keep going many levels down. It doesn't follow symlinks though so it shouldn't get stuck in recursion loops. It uses os.walk for the recursion.