community.windows.win_robocopy (2.2.0) — module

Synchronizes the contents of two directories using Robocopy

Authors: Corwin Brown (@blakfeld)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

Synchronizes the contents of files/directories from a source to destination.

Under the hood this just calls out to RoboCopy, since that should be available on most modern Windows systems.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Sync the contents of one directory to another
  community.windows.win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Sync the contents of one directory to another, including subdirectories
  community.windows.win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    recurse: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Sync the contents of one directory to another, and remove any files/directories found in destination that do not exist in the source
  community.windows.win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    purge: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Sync content in recursive mode, removing any files/directories found in destination that do not exist in the source
  community.windows.win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    recurse: yes
    purge: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Sync two directories in recursive and purging mode, specifying additional special flags
  community.windows.win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    flags: /E /PURGE /XD SOME_DIR /XF SOME_FILE /MT:32
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Sync one file from a remote UNC path in recursive and purging mode, specifying additional special flags
  community.windows.win_robocopy:
    src: \\Server1\Directory One
    dest: C:\DirectoryTwo
    flags: file.zip /E /PURGE /XD SOME_DIR /XF SOME_FILE /MT:32

Inputs

    
src:
    description:
    - Source file/directory to sync.
    required: true
    type: path

dest:
    description:
    - Destination file/directory to sync (Will receive contents of src).
    required: true
    type: path

flags:
    description:
    - Directly supply Robocopy flags.
    - If set, C(purge) and C(recurse) will be ignored.
    type: str

purge:
    default: false
    description:
    - Deletes any files/directories found in the destination that do not exist in the
      source.
    - Toggles the C(/purge) flag to RoboCopy.
    - If C(flags) is set, this will be ignored.
    type: bool

recurse:
    default: false
    description:
    - Includes all subdirectories (Toggles the C(/e) flag to RoboCopy).
    - If C(flags) is set, this will be ignored.
    type: bool

Outputs

cmd:
  description: The used command line.
  returned: always
  sample: robocopy C:\DirectoryOne C:\DirectoryTwo /e /purge
  type: str
dest:
  description: The Destination file/directory of the sync.
  returned: always
  sample: C:\Some\Path
  type: str
flags:
  description: Any flags passed in by the user.
  returned: always
  sample: /e /purge
  type: str
msg:
  description: Output interpreted into a concise message.
  returned: always
  sample: No files copied!
  type: str
output:
  description: The output of running the robocopy command.
  returned: success
  sample: '------------------------------------\n   ROBOCOPY     ::     Robust File
    Copy for Windows         \n------------------------------------\n '
  type: str
purge:
  description: Whether or not the purge flag was toggled.
  returned: always
  sample: false
  type: bool
rc:
  description: The return code returned by robocopy.
  returned: success
  sample: 1
  type: int
recurse:
  description: Whether or not the recurse flag was toggled.
  returned: always
  sample: false
  type: bool
src:
  description: The Source file/directory of the sync.
  returned: always
  sample: C:\Some\Path
  type: str

See also