功能:sync數據同步文件等
參數:
archive: 是否采用地規模上同步
compress:開啟壓縮默認為開啟
copy_links: 同步是否復制連接
delete: 刪除源中沒有而目標文件存在文件
dest= 目標地址
dirs 以非遞歸的方式傳輸目錄
mode: push或pull,默認為push
recursive 是否遞歸
rsync_opts 使用rsync的參數
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包
拉取遠程主機的文件到文件
[admin@node1 tmp]$ ansible 192.168.20.138 -m synchronize -a "src=/etc/nginx/nginx.conf dest=/tmp mode=pull"
192.168.20.138 | SUCCESS => {
"changed": false,
"cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o Port=1050 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --out-format=<<CHANGED>>%i %n%L 192.168.20.138:/etc/nginx/nginx.conf /tmp",
"msg": "",
"rc": 0,
"stdout_lines": []
}
- 第一章:Ansible基礎入門
- 第二章:Ansible系列手冊
- 第一節:Ansible系列之主機清單
- 第二節:Ansible系列之變量
- 第三節:Ansible系列之YAML
- 第四節:Ansible系列之條件判斷
- 第五節:Ansible系列之循環
- 第六節: Ansible系列之tags
- 第七節:Ansible系列之Jinja2
- 第三章:Ansible系列之模塊
- 第一節:user模塊
- 第二節:group模塊
- 第三節:cron模塊
- 第四節:copy模塊
- 第五節: file模塊
- 第六節:yum模塊
- 第七節:service模塊
- 第八節:shell模塊
- 第九節:script模塊
- 第十節:setup模塊
- 第十一節:filesystem和mount模塊
- 第十二節:synchronize模塊
- 第十三節: get_url模塊
- 第十四節: package模塊
- 第十五節:stat模塊
- 第十六節:unarchive模塊
- 第十七節: commang模塊
- 第四章:Ansible-playbook介紹
- 第五章:Ansible系統環境
- 第一節:Ansible Role 系統環境之epel設置