ansible copy文件比较慢, 使用Synchronize模块

十一、Ansible中的同步模块(rsync)

 

Synchronize模块
1
2
3
4
5
6
7
   This is a wrapper around rsync. Of course you could just use the
   command action to call rsync yourself, but you also have to add a
   fair number of boilerplate options and host facts. You still may
   need to call rsync directly via `command' or `shell' depending on
   your use case. The synchronize action is meant to do common things
   with `rsync' easily. It does not provide access to the full power of
   rsync, but does make most invocations easier to follow.

这是一个关于rsync的模块。

参数

必填

默认值

选项

说明

archive

no

yes

yes

 no

显示rsync的存档标志所属信息

checksum

no

no

 yes

  no

校验

compress

no

yes

yes

 no

在传送过程中压缩文件数据

dest

yes

  

目标路径,路径可以绝对或相对

delete

no

no

yes

no

删除srv中不存在的文件

copy_links

no

no

yes

no

复制符号链接,是映射的文件复制

dest_port

no

22

yes

no

目标主机端口号(ansible_ssh_port优先于此值)

group

no

存档选项值

yes

no

保留文件的所属组

owner

no

存档选项值

yes

no

保留文件的所属者(只有超级用户可以操作)

perms

no

存档选项值

yes

no

保留文件的权限

rsync_opts

no

no

 

通过此选项指定其他的rsync的选项

rsync_path

no

  

指定rsync命令到远程主机上运行

rsync_timeout

no

0

 

指定rsync的timeout时间以秒为单位

src

yes

  

源地址(路径可以是绝对或相对的)

times

no

存档选项值

yes

no

保留文件的修改时间

exclude-from

no

no

yes

no

用于定义排除多个文件夹和文件

exclude

no

no

yes

no

用于定义排除单独的文件夹和文件

实例展示: 
1
2
3
4
5
6
---
- hosts: web
   remote_user: deploy
   tasks:
     - name: webserver update web server (--exclude-file)
       synchronize: src=/home/deploy/webserver/  dest=/data/web/webserver/ rsync_opts=--delete,--exclude-from=/data/ansible/public/excludefile

 

 实际使用:比用copy模块速度增加很多

cat stbverify_update.yml
---
- name: handlers adserver
hosts: adservers
user: root
tasks:
- name: copy file
synchronize: src=/etc/ansible/STBVerify dest=/root/ rsync_opts=--delete
notify: stbverify handlers
handlers:
- name: stbverify handlers
shell: /bin/bash /data/sh/stbverify_update.sh

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值