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

原文:https://www.cnblogs.com/weifeng1463/p/8484316.html

ansible进阶:https://www.ibm.com/developerworks/cn/linux/1608_lih_ansible/index.html

最新文章

  1. 给缺少Python项目实战经验的人
  2. VBA的一些使用心得
  3. commonJS — 数字操作(for Number)
  4. 1.PHP站内搜索 分类: PHP开发实例 2015-07-31 22:48 4人阅读 评论(0) 收藏
  5. 学Lua(上)
  6. python操作redis-过期时间
  7. easy_install MySQL-python
  8. 【NOIP2016 Day1 T2】天天爱跑步
  9. ③bootstrap文本使用基础案例
  10. angular.js学习的第一天
  11. java项目发布到linux服务器,tomcat正常启动但没加载项目
  12. maven ${path.separator}
  13. vue项目中使用axios上传图片等文件
  14. css3整理--border-image
  15. 论文笔记之《Event Extraction via Dynamic Multi-Pooling Convolutional Neural Network》
  16. C语言数据结构与算法之深度、广度优先搜索
  17. centos_7.1.1503_src_4
  18. 赢在面试之Java多线程(十一)
  19. 【数据结构】单链表&&静态链表详解和代码实例
  20. MFC接收ShellExecute多个参数

热门文章

  1. Win8.1应用开发之Bing Maps
  2. 基于Android Classic Bluetooth的蓝牙聊天软件
  3. NHibernate利用Mindscape.NHibernateModelDesigner实现数据库与实体之间的转换及操作
  4. Python Numpy 数组的初始化和基本操作
  5. struts2中怎样处理404?
  6. Spring事务管理简介
  7. Python内置函数之sorted()
  8. unity开发android游戏(一)搭建Unity安卓开发环境
  9. NHibernate 延迟加载与立即加载 (第七篇)
  10. Google Code Jam 2014 Round 1 A:Problem A Charging Chaos