From a8fbfe1844177ad0e53d6eec95efb4775c806483 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 28 Nov 2018 18:47:55 -0800 Subject: [PATCH] Warn if empty string is present in synchronize's rsync_opts --- changelogs/fragments/synchronize-warning.yaml | 4 ++++ lib/ansible/modules/files/synchronize.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/synchronize-warning.yaml diff --git a/changelogs/fragments/synchronize-warning.yaml b/changelogs/fragments/synchronize-warning.yaml new file mode 100644 index 00000000000..b9e5bbb0453 --- /dev/null +++ b/changelogs/fragments/synchronize-warning.yaml @@ -0,0 +1,4 @@ +--- +minor_changes: +- synchronize module - Warn when the empty string is present in rsync_opts as it is likely + unexpected that it will transfer the current working directory. diff --git a/lib/ansible/modules/files/synchronize.py b/lib/ansible/modules/files/synchronize.py index 8737986f824..a044d3ea290 100644 --- a/lib/ansible/modules/files/synchronize.py +++ b/lib/ansible/modules/files/synchronize.py @@ -132,7 +132,8 @@ options: version_added: "2.0" rsync_opts: description: - - Specify additional rsync options by passing in an array. + - Specify additional rsync options by passing in an array. Note that an empty string in + C(rsync_opts) will end up transfer the current working directory. default: version_added: "1.6" partial: @@ -519,6 +520,11 @@ def main(): cmd.append('--rsync-path=%s' % rsync_path) if rsync_opts: + if '' in rsync_opts: + module.warn('The empty string is present in rsync_opts which will cause rsync to' + ' transfer the current working directory. If this is intended, use "."' + ' instead to get rid of this warning. If this is unintended, check for' + ' problems in your playbook leading to empty string in rsync_opts.') cmd.extend(rsync_opts) if partial: @@ -559,10 +565,10 @@ def main(): # Ignore broken pipe errors if the sshpass process has exited. if exc.errno != errno.EPIPE or proc.poll() is None: raise + (rc, out, err) = module.run_command( cmd, pass_fds=_sshpass_pipe, - before_communicate_callback=_write_password_to_pipe - ) + before_communicate_callback=_write_password_to_pipe) else: (rc, out, err) = module.run_command(cmd)