ansible.builtin.win_robocopy (v2.3.0.0-1) — module

Synchronizes the contents of two directories using Robocopy.

| "added in version" 2.2 of ansible.builtin"

Authors: Corwin Brown (@blakfeld)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.3.0.0.post1

Description

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.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Sync the contents of one directory to another
  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
  win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    recurse: True
  • 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
  win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    purge: True
  • 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
  win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    recurse: True
    purge: True
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

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

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

flags:
    default: None
    description:
    - Directly supply Robocopy flags. If set, purge and recurse will be ignored.
    required: false

purge:
    choices:
    - true
    - false
    default: false
    description:
    - 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.
    required: false

recurse:
    choices:
    - true
    - false
    default: false
    description:
    - Includes all subdirectories (Toggles the `/e` flag to RoboCopy). If "flags" is set,
      this will be ignored.
    required: false

Outputs

changed:
  description: Whether or not any changes were made.
  returned: always
  sample: false
  type: bool
dest:
  description: The Destination file/directory of the sync.
  returned: always
  sample: c:\Some\Path
  type: string
flags:
  description: Any flags passed in by the user.
  returned: always
  sample: /e /purge
  type: string
msg:
  description: Output intrepreted into a concise message.
  returned: always
  sample: No files copied!
  type: string
output:
  description: The output of running the robocopy command.
  returned: success
  sample: "-------------------------------------------------------------------------------\n\
    \   ROBOCOPY     ::     Robust File Copy for Windows                         \
    \     \n-------------------------------------------------------------------------------\n"
  type: string
purge:
  description: Whether or not the purge flag was toggled.
  returned: always
  sample: false
  type: bool
rc:
  description: The return code retuned 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: string