ansible之synchronize模块数据同步

ansible之synchronize模块数据同步

选项说明
archive # 是否采用归档模式同步,即以源文件相同属性同步到目标地址
checksum # 是否效验
compress # 开启压缩,默认为开启
copy_links # 同步的时候是否复制连接
delete # 删除源中没有而目标存在的文件(即以推送方为主)
dest= # 目标地址
dest_port # 目标接受的端口,ansible配置文件中的 ansible_ssh_port 变量优先级高于该 dest_port 变量
dirs # 以非递归的方式传输目录
existing_only # Skip creating new files on receiver.
group # Preserve group
links # Copy symlinks as symlinks.
mode # 模式,rsync 同步的方式 PUSH\PULL,默认都是推送push。如果你在使用拉取pull功能的时候,可以参考如下来实现mode=pull 更改推送模式为拉取模式
recursive # 是否递归 yes/no
rsync_opts # 使用rsync 的参数
rsync_path # 服务的路径,指定 rsync 命令来在远程服务器上运行。这个参考rsync命令的--rsync-path参数,--rsync-path=PATH # 指定远程服务器上的rsync命令所在路径信息
rsync_timeout # 指定 rsync 操作的 IP 超时时间,和rsync命令的 --timeout 参数效果一样.
set_remote_user # put user@ for the remote paths. If you have a custom ssh config to define the remote user for
src= # 源,同步的数据源
times #
--exclude=.Git 忽略同步.git结尾的文件
由于模块默认启用了archive参数,该参数默认开启了recursive, links, perms, times, owner,group和-D参数。如果你将该参数设置为no,那么你将停止很多参数,比如会导致如下目的递归失败,导致无法拉取
使用rsync 模块,系统必须安装rsync 包,否则无法使用这个模块
[root@ansible ~]# ansible web -m synchronize -a 'src=time.sh dest=/tmp/'
web | FAILED! => {
"changed": false,
"failed": true,
"msg": "Failed to find required executable rsync"
}
安装rsync
[root@ansible ~]# ansible web -a 'yum install rsync -y'
web | SUCCESS | rc=0 >>
Loaded plugins: fastestmirror
Determining fastest mirrors

  • base: mirrors.opencas.cn
  • extras: mirrors.opencas.cn
  • updates: mirrors.opencas.cn
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package rsync.x86_64 0:3.0.6-12.el6 will be installed
    --> Finished Dependency Resolution
    Dependencies Resolved

    Package Arch Version Repository Size

    Installing:
    rsync x86_64 3.0.6-12.el6 base 335 k
    Transaction Summary

    Install 1 Package(s)
    Total download size: 335 k
    Installed size: 682 k
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
    Installing : rsync-3.0.6-12.el6.x86_64 1/1
    Verifying : rsync-3.0.6-12.el6.x86_64 1/1
    Installed:
    rsync.x86_64 0:3.0.6-12.el6
    Complete!

示例,吧本机的epel-release-latest-6.noarch.rpm拷贝到web主机上。
ansible之synchronize模块数据同步
吧tom目录推送到web主机上的/tmp目录下
ansible之synchronize模块数据同步

拉取web主机上的zabbix目录到本地的/opt目录下
ansible之synchronize模块数据同步
拉取模式mode=pull
ansible之synchronize模块数据同步
验证下是否拉取到本地的/opt目录下
ansible之synchronize模块数据同步
数据同步文件就先到这了。。。。

转载于:https://blog.51cto.com/lookingdream/2048702

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值