From 7511421440dd5acf68e60fcfad9a8de6455638d5 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Sat, 3 Apr 2021 16:22:10 +0430 Subject: [PATCH 1/4] Add delay_updates option to synchronize module --- plugins/modules/synchronize.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 77a093112a..5c4d50d95b 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -178,6 +178,12 @@ type: list default: elements: str + delay_updates: + description: + - This option puts the temporary file from each updated file into a holding directory until the end of the transfer, + at which time all the files are renamed into place in rapid succession. + type: bool + default: yes notes: - rsync must be installed on both the local and remote host. @@ -199,8 +205,8 @@ - Inspect the verbose output to validate the destination user/host/path are what was expected. - To exclude files and directories from being synchronized, you may add 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. - - The C(synchronize) module forces `--delay-updates` to avoid leaving a destination in a broken in-between state if the underlying rsync process - encounters an error. Those synchronizing large numbers of files that are willing to trade safety for performance should call rsync directly. + - The C(synchronize) module enables `--delay-updates` by default to avoid leaving a destination in a broken in-between state if the underlying rsync process + encounters an error. Those synchronizing large numbers of files that are willing to trade safety for performance should disable this option. - link_destination is subject to the same limitations as the underlying rsync daemon. Hard links are only preserved if the relative subtrees of the source and destination are the same. Attempts to hardlink into a directory that is a subdirectory of the source will be prevented. seealso: @@ -408,6 +414,7 @@ def main(): ssh_connection_multiplexing=dict(type='bool', default=False), partial=dict(type='bool', default=False), verify_host=dict(type='bool', default=False), + delay_updates=dict(type='bool', default=True), mode=dict(type='str', default='push', choices=['pull', 'push']), link_dest=dict(type='list', elements='str'), ), @@ -449,11 +456,15 @@ def main(): ssh_connection_multiplexing = module.params['ssh_connection_multiplexing'] verify_host = module.params['verify_host'] link_dest = module.params['link_dest'] + delay_updates = module.params['delay_updates'] if '/' not in rsync: rsync = module.get_bin_path(rsync, required=True) - cmd = [rsync, '--delay-updates', '-F'] + cmd = [rsync] + if delay_updates: + cmd.append('--delay_updates') + cmd.append('-F') _sshpass_pipe = None if rsync_password: try: From fc9fce718d0e9b585eab08be13c74bf2c572baf4 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Sat, 3 Apr 2021 16:24:53 +0430 Subject: [PATCH 2/4] Add changelog --- changelogs/fragments/167-synchronize-add_delay_option.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/167-synchronize-add_delay_option.yml diff --git a/changelogs/fragments/167-synchronize-add_delay_option.yml b/changelogs/fragments/167-synchronize-add_delay_option.yml new file mode 100644 index 0000000000..38070f4ca5 --- /dev/null +++ b/changelogs/fragments/167-synchronize-add_delay_option.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - synchronize - add ``delay_updates`` option (https://github.com/ansible-collections/ansible.posix/issues/157). From 9313bf3e68b25fe7ad177258ede6208fee9021e8 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Mon, 26 Apr 2021 10:58:27 +0430 Subject: [PATCH 3/4] Reorder if to address quidame suggestion --- plugins/modules/synchronize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 5c4d50d95b..7faef18d5b 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -462,9 +462,6 @@ def main(): rsync = module.get_bin_path(rsync, required=True) cmd = [rsync] - if delay_updates: - cmd.append('--delay_updates') - cmd.append('-F') _sshpass_pipe = None if rsync_password: try: @@ -475,6 +472,9 @@ def main(): ) _sshpass_pipe = os.pipe() cmd = ['sshpass', '-d' + to_native(_sshpass_pipe[0], errors='surrogate_or_strict')] + cmd + if delay_updates: + cmd.append('--delay_updates') + cmd.append('-F') if compress: cmd.append('--compress') if rsync_timeout: From 54ea8777f86e241d86420090f868e2985b3d4729 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Thu, 27 May 2021 19:31:40 +0430 Subject: [PATCH 4/4] add version_added to new option Co-authored-by: Abhijeet Kasurde --- plugins/modules/synchronize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 7faef18d5b..895754a544 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -184,6 +184,7 @@ at which time all the files are renamed into place in rapid succession. type: bool default: yes + version_added: '1.3.0' notes: - rsync must be installed on both the local and remote host.