十一、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