added rsync protocol support (#1999)

* added rsync protocol support

* correction for example document(add example for push on delegate)

* use startswith method for safety
This commit is contained in:
peter.jang 2016-04-09 00:41:53 +09:00 committed by Matt Clay
parent 64cd7903f2
commit f7fb5e31c2

View file

@ -176,6 +176,8 @@ notes:
are what was expected. are what was expected.
- To exclude files and directories from being synchronized, you may add - To exclude files and directories from being synchronized, you may add
C(.rsync-filter) files to the source directory. C(.rsync-filter) files to the source directory.
- rsync daemon must be up and running with correct permission when using
rsync protocol in source or destination path.
author: "Timothy Appnel (@tima)" author: "Timothy Appnel (@tima)"
@ -185,6 +187,22 @@ EXAMPLES = '''
# Synchronization of src on the control machine to dest on the remote hosts # Synchronization of src on the control machine to dest on the remote hosts
synchronize: src=some/relative/path dest=/some/absolute/path synchronize: src=some/relative/path dest=/some/absolute/path
# Synchronization using rsync protocol (push)
synchronize: src=some/relative/path/ dest=rsync://somehost.com/path/
# Synchronization using rsync protocol (pull)
synchronize: mode=pull src=rsync://somehost.com/path/ dest=/some/absolute/path/
# Synchronization using rsync protocol on delegate host (push)
synchronize: >
src=/some/absolute/path/ dest=rsync://somehost.com/path/
delegate_to: delegate.host
# Synchronization using rsync protocol on delegate host (pull)
synchronize: >
mode=pull src=rsync://somehost.com/path/ dest=/some/absolute/path/
delegate_to: delegate.host
# Synchronization without any --archive options enabled # Synchronization without any --archive options enabled
synchronize: src=some/relative/path dest=/some/absolute/path archive=no synchronize: src=some/relative/path dest=/some/absolute/path archive=no
@ -389,10 +407,14 @@ def main():
if ssh_args: if ssh_args:
ssh_opts = '%s %s' % (ssh_opts, ssh_args) ssh_opts = '%s %s' % (ssh_opts, ssh_args)
if dest_port != 22: if source.startswith('rsync://') and dest.startswith('rsync://'):
cmd += " --rsh '%s %s %s -o Port=%s'" % (ssh, private_key, ssh_opts, dest_port) module.fail_json(msg='either src or dest must be a localhost', rc=1)
else:
cmd += " --rsh '%s %s %s'" % (ssh, private_key, ssh_opts) # need ssh param if not source.startswith('rsync://') and not dest.startswith('rsync://'):
if dest_port != 22:
cmd += " --rsh 'ssh %s %s -o Port=%s'" % (private_key, ssh_opts, dest_port)
else:
cmd += " --rsh 'ssh %s %s'" % (private_key, ssh_opts) # need ssh param
if rsync_path: if rsync_path:
cmd = cmd + " --rsync-path=%s" % (rsync_path) cmd = cmd + " --rsync-path=%s" % (rsync_path)