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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端