community.windows.win_robocopy 模块 – 使用 Robocopy 同步两个目录的内容
注意
此模块是 community.windows 集合 (版本 2.3.0) 的一部分。
如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.windows。
要在 playbook 中使用它,请指定:community.windows.win_robocopy。
概要
- 同步文件/目录的内容从源到目标。 
- 在底层,这只是调用 RoboCopy,因为这应该在大多数现代 Windows 系统上可用。 
参数
| 参数 | 注释 | 
|---|---|
| 要同步的目标文件/目录(将接收 src 的内容)。 | |
| 直接提供 Robocopy 标志。 如果设置,则会忽略  | |
| 删除目标中在源中不存在的任何文件/目录。 将  如果设置了  选项 
 | |
| 包含所有子目录(将  如果设置了  选项 
 | |
| 要同步的源文件/目录。 | 
备注
注意
- 这不是 ansible.posix.synchronize 模块的完整移植。与 ansible.posix.synchronize 模块不同,此模块仅在远程计算机上执行同步/复制操作,而不是从 Ansible 控制器到远程计算机。 
- 此模块目前不支持所有 Robocopy 标志。 
另请参见
另请参见
- ansible.posix.synchronize
- 围绕 rsync 的一个包装器,用于使 playbook 中的常见任务快速简便。 
- ansible.windows.win_copy
- 将文件复制到 Windows 主机的远程位置。 
示例
- name: Sync the contents of one directory to another
  community.windows.win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
- name: Sync the contents of one directory to another, including subdirectories
  community.windows.win_robocopy:
    src: C:\DirectoryOne
    dest: C:\DirectoryTwo
    recurse: true
- 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: true
- 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: true
    purge: true
- 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
- 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
返回值
公共返回值已在此处记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 使用的命令行。 返回:始终 示例: | |
| 同步的目标文件/目录。 返回:始终 示例: | |
| 用户传入的任何标志。 返回:始终 示例: | |
| 解释成简洁消息的输出。 返回:始终 示例: | |
| 运行 robocopy 命令的输出。 返回:成功 示例: | |
| 是否切换了 purge 标志。 返回:始终 示例: | |
| robocopy 返回的返回码。 返回:成功 示例: | |
| 是否切换了 recurse 标志。 返回:始终 示例: | |
| 同步的源文件/目录。 返回:始终 示例: | 
