选项说明
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 ResolvedPackage Arch Version Repository Size
Installing:
rsync x86_64 3.0.6-12.el6 base 335 k
Transaction SummaryInstall 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主机上。
吧tom目录推送到web主机上的/tmp目录下
拉取web主机上的zabbix目录到本地的/opt目录下
拉取模式mode=pull
验证下是否拉取到本地的/opt目录下
数据同步文件就先到这了。。。。
转载于:https://blog.51cto.com/lookingdream/2048702