On this page
win_robocopy - Synchronizes the contents of two directories using Robocopy
New in version 2.2.
Synopsis
- Synchronizes the contents of two directories on the remote machine.
- Under the hood this just calls out to RoboCopy, since that should be available on most modern Windows Systems.
Options
parameter | required | default | choices | comments |
---|---|---|---|---|
dest |
yes |
Destination file/directory to sync (Will receive contents of src).
|
||
flags |
no |
Directly supply Robocopy flags. If set, purge and recurse will be ignored.
|
||
purge |
no | no |
|
Deletes any files/directories found in the destination that do not exist in the source.
Toggles the /purge flag to RoboCopy. If flags is set, this will be ignored.
|
recurse |
no | no |
|
Includes all subdirectories (Toggles the
/e flag to RoboCopy).
If flags is set, this will be ignored.
|
src |
yes |
Source file/directory to sync.
|
Examples
- name: Sync the contents of one directory to another
win_robocopy:
src: C:\DirectoryOne
dest: C:\DirectoryTwo
- name: Sync the contents of one directory to another, including subdirectories
win_robocopy:
src: C:\DirectoryOne
dest: C:\DirectoryTwo
recurse: yes
- name: Sync the contents of one directory to another, and remove any files/directories found in destination that do not exist in the source
win_robocopy:
src: C:\DirectoryOne
dest: C:\DirectoryTwo
purge: yes
- name: Sync content in recursive mode, removing any files/directories found in destination that do not exist in the source
win_robocopy:
src: C:\DirectoryOne
dest: C:\DirectoryTwo
recurse: yes
purge: yes
- name: Sync two directories in recursive and purging mode, specifying additional special flags
win_robocopy:
src: C:\DirectoryOne
dest: C:\DirectoryTwo
flags: /E /PURGE /XD SOME_DIR /XF SOME_FILE /MT:32
Return Values
Common return values are documented here Return Values, the following are the fields unique to this module:
name | description | returned | type | sample |
---|---|---|---|---|
cmd |
The used command line
|
always | string | robocopy C:\DirectoryOne C:\DirectoryTwo /e /purge |
dest |
The Destination file/directory of the sync.
|
always | string | C:\Some\Path |
flags |
Any flags passed in by the user.
|
always | string | /e /purge |
msg |
Output intrepreted into a concise message.
|
always | string | No files copied! |
output |
The output of running the robocopy command.
|
success | string | ------------------------------------\n ROBOCOPY :: Robust File Copy for Windows \n------------------------------------\n |
purge |
Whether or not the purge flag was toggled.
|
always | bool | False |
rc |
The return code returned by robocopy.
|
success | int | 1 |
recurse |
Whether or not the recurse flag was toggled.
|
always | bool | False |
src |
The Source file/directory of the sync.
|
always | string | C:\Some\Path |
Notes
Note
- This is not a complete port of the synchronize module. Unlike the synchronize module this only performs the sync/copy on the remote machine, not from the master to the remote machine.
- This module does not currently support all Robocopy flags.
Status
This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.
For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.4/win_robocopy_module.html