用来进行被控端与控制端之间的文件同步传输,直接看例子理解即可

使用该模块首先要在控制端和被控端安装有rsync

控制端传输被控端

- hosts: 192.168.1.1     # 远端主机
  remote_user:root   # 远端主机的操作用户
  task:
    - name: controll to node
      synchronize:
        src: /xxx/xxx    # 控制端路径
        dest: /.../...   # 远端主机路径
        mode: push       # 默认为push可不写

控制端拉取被控端

- hosts: 192.168.1.1     # 远端主机
  remote_user:root   # 远端主机的操作用户
  task:
    - name: controll to node
      synchronize:
        src: /xxx/xxx    # 远端主机路径
        dest: /.../...   # 控制端路径
        mode: pull       # 默认为push可不写

控制端控制多远端之间同步

- hosts: 192.168.1.1     # 远端主机B
  remote_user:root   # 远端主机的操作用户
  task:
    - name: A→B
      synchronize:
        src: /xxx/xxx    # 远端主机A路径
        dest: /.../...   # 远端主机B路径
        mode: push       # 默认为push可不写
      delegate_to: 192.168.1.2  # 远端主机A
    - name: B→A
      synchronize:
        src: /xxx/xxx    # 远端主机B路径
        dest: /.../...   # 远端主机A路径
        mode: pull
      delegate_to: 192.168.1.2  # 远端主机A

评论




正在载入...
PoweredHexo
HostedAliyun
DNSAliyun
ThemeVolantis
UV
PV
BY-NC-SA 4.0