With the introduction of action plugins, I decided to develop a rsync module to use with Ansible.
Users always have the option to run rsync directly with the command module and choose any of its many many options. I wanted something that would keep things simple -- options to a minimum, "smart" defaults and integrating as much of its operation to parameters and facts Ansible is running with.
This is what I came up with so far and want to get some feedback from the list: https://github.com/tima/ansible-rsync/blob/master/lib/ansible/runner/action_plugins/rsync.py
I am assuming --archive operations only that use the temp directory created by Ansible and delays updates (--delay-updates) until everyting is complete so destinations are not left in some in-between state. All file transfers will be compressed and tunneled over SSH using the configured private key. The optional delete option will use --delete-after to also make sure the destination is not left in some in-between state.
I implemented a mode attribute that specifies if the files are being sent from the controller to a remote node mode=copy -- the default) or the other way around (mode=fetch). The mode attribute is only considered if the connection is not local. I used copy and fetch to coincide to the modules in Ansible though I would have preferred push and pull.
Here is how you use it in its most basic form:
action: rsync src=/path/to/src dest=/path/to/dest
To sync the local file system with a remote node:
action: mode=fetch rsync src=/path/to/src dest=/path/to/dest
To clear out any files not in your source:
action: rsync src=/path/to/src dest=/path/to/dest delete=true
By default rsync runs in quiet mode, but if you want want input feedback on what rsync did:
action: rsync src=/path/to/src dest=/path/to/dest verbosity=1
The number given to verbosity corresponds to the number of 'v' that is being passed to rsync. A value of 1 is some output and 3 is a lot of output only useful for debugging.
One last feature I have implemented is one I needed at my day job. The ability to specify which/where rsync is being run on the remote. Similar to how Ansible deals with the location of the python intrepreter, the path to the rsync to use can be set with a host variable of ansible_rsync_path in your inventory.
I need to implement a way to declare the local version of rsync to use, but I'm not sure what's the right way for a plugin to implement a configuration param currently. (Michael?)
Other features I'd considered was logging and include/exclude file options, but had questions on how to best implement those so I set them aside for now.
Thoughts?
<tim/>