Ansible同步模块 ansible



Ansible同步模块

1.    synchronize 模块

功能: 数据同步管理  使用此模块需要服务端与web组都安装了rsync.

#ansible webs -m shell -a "rpm -qa rsync"   检查是否安装了rsync

192.168.0.28 | SUCCESS | rc=0 >>

rsync-3.0.9-17.el7.x86_64

安装rsync

#ansible web -m shell -a "yum install rsync"

同步目录:

#ansible webs -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ "

同步目录,删除目的目录中源目录中没有的文件

#ansible webs -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ delete=yes"

"msg": "*deleting   test.txt\n"

同步目录,排除某个文件

ansible webs -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ rsync_opts="--exclude=exclude.txt" "

同步目录,排除多个文件

ansible webs -m synchronize -a "src=/data/adminshell/ dest=/data/adminshell/ rsync_opts="--exclude=\*.conf,--exclude=\*.html,--exclude=test1" "

上线测试语句:

# ansible test -m synchronize -a "src=/home/xin.nie/1.6.9/ dest=/root/asbtest/ delete=yes rsync_opts="--exclude=.svn,--exclude=Uploads,--exclude=WeiZuanHtml5,--exclude=Runtime,--exclude=\*.log,--exclude=\*.gz,--exclude=\*.zip,--exclude=id,--exclude=Html,--exclude=Conf,--exclude=\*.apk,--exclude=sharefile,--exclude=version.txt" "

 

#ansible-doc -s synchronize   模块用法

 选型说明:

      archive                # 是否采用归档模式,即以源文件相同属性同步到目标地址。默认开启

      checksum               # 是否校验 (yse,no)默认no                     

      compress               # 开启压缩,默认开启

      copy_links             # 同步时是否复制链接(yse,no)默认no

      delete                 # 删除源中没有而目标存在的文件(即以推送方为主)                     

      dest=                  # 目标地址

      dest_port              # 目标接受的端口号,ansible配置文件中的ansible_ssh_port变量优先级高于该dest_port变量                 

      dirs                   # 以非递归的方式传输目录(yse,no)默认no

      existing_only          # Skip creating new files on receiver.

      group                  # Preserve group

      links                  # Copy symlinks as symlinks.

      mode                   # 模式,rsync 同步的方式 PUSH\PULL,默认都是推送push。如果你在使用拉取pull功能的时候,可以参考如下来实现mode=pull   更改推送模式为拉取模式

      owner                  # Preserve owner (super user only)

      partial                # Tells rsync to keep the partial file which should make a subsequent transfer of the rest of the file much

                               faster.

      perms                  # Preserve permissions.

      recursive              # Recurse into directories.

      rsync_opts             # Specify additional rsync options by passing in an array.

      rsync_path             # Specify the rsync command to run on the remote host. See `--rsync-path' on the rsync man page.

      rsync_timeout          # 指定rsync操作的IP超时时间,单位s.

set_remote_user        # put user@ for the remote paths. If you have a custom ssh config to define the remote user

                               not match the inventory user, you should set this parameter to "no".

      src=                   # Path on the source host that will be synchronized to the destination; The path can be abso

      times                  # Preserve modification times

      use_ssh_args           # Use the ssh_args specified in ansible.cfg

      verify_host            # Verify destination host key.

 


签名:这个人很懒,什么也没有留下!
最新回复 (0)
返回