sync数据同步文件等,官方栗子http://docs.ansible.com/ansible/synchronize_module.html
用法
[[email protected] ~]# ansible-doc -s synchronize
less 436
Copyright (C) 1984-2009 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
- name: Uses rsync to make synchronizing file paths in your playbooks quick and easy.
action: synchronize
archive # Mirrors the rsync archive flag, enables recursive, links, perms, times, owner, group flags and
-D.
checksum # Skip based on checksum, rather than mod-time & size; Note that that "archive" option is still
enabled by default - the "checksum" option will not disable it.
compress # Compress file data during the transfer. In most cases, leave this enabled unless it causes
problems.
copy_links # Copy symlinks as the item that they point to (the referent) is copied, rather than the symlink.
delete # Delete files that don‘t exist (after transfer, not before) in the `src‘ path. This option
requires `recursive=yes‘.
dest= # Path on the destination host that will be synchronized from the source; The path can be absolute
or relative.
dest_port # Port number for ssh on the destination host. Prior to ansible 2.0, the ansible_ssh_port inventory
var took precedence over this value.
dirs # Transfer directories without recursing
existing_only # Skip creating new files on receiver.
group # Preserve group
links # Copy symlinks as symlinks.
mode # Specify the direction of the synchronization. In push mode the localhost or delegate is the
source; In pull mode the remote host in context is the source.
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 # Specify a --timeout for the rsync command in seconds.
set_remote_user # put [email protected] for the remote paths. If you have a custom ssh config to define the remote user for a
host that does not match the inventory user, you should set this
parameter to "no".
src=\‘#\‘" /pre>
选项说明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 [email protected] 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 包,否则无法使用这个模块
[[email protected] ~]# ansible web -m synchronize -a ‘src=time.sh dest=/tmp/‘
web | FAILED! => {
"changed": false,
"failed": true,
"msg": "Failed to find required executable rsync"
}
安装rsync
[[email protected] ~]# 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!
未完待续
示例
时间: 2024-10-18 00:32:41