ansile(2)模块之synchronize
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,ansible synchronize作用跟rsync很相似,具体参数如下:参数内容,均来自官网,如果有出入,以官网为主参数是否必须默认选项说明archivenoyesyesnorsync镜像递归标志
千家信息网最后更新 2025年02月02日ansile(2)模块之synchronize
ansible synchronize作用跟rsync很相似,具体参数如下:
参数内容,均来自官网,如果有出入,以官网为主
参数 | 是否必须 | 默认 | 选项 | 说明 |
archive | no | yes | yes no | rsync镜像递归标志,启用递归,链接,权限,时间,属主,属组标志和 -D |
checksum | no | no | yes no | 跳过基本的校验 |
compress | no | yes | yes no | 在传输过程中压缩文件数据。在大多数情况下,请保持启用,除非它导致问题。 |
copy_links | no | no | yes no | 将符号链接复制为它们所指向的项(引用对象),而不是符号链接。 |
delete | no | no | yes no | 删除src路径中不存在的dest中的文件(传输后,不在之前)。此选项需要recursive = yes。 |
dest | yes | 要同步源的目标主机上的路径;该路径可以是绝对路径或相对路径。 | ||
dest_port | no | ansible_ssh_port的值设定,remote_port配置设置,如果ssh客户端没有设置的话 | 目标主机上ssh的端口号。在ansible 2.0之前,ansible_ssh_port库存变量优先于此值。 | |
dirs | no | no | yes no | 传输目录而不进行递归 |
existing_only | no | no | yes no | 跳过在接收器上创建一个新文件。 |
group | no | 递归选项的值 | yes no | 保留组 |
links | no | 递归选项的值 | yes no | 将符号链接复制为符号链接。 |
mode | no | push | yes no | 指定同步的方向。在推模式下,localhost或delegate是源;在拉模式下,远程主机在上下文中是源。 |
owner | no | 递归选项的值 | yes no | 保留属主 |
partial | no | 告诉rsync保留一些文件,这应该使以后的文件传输的其余部分。 | ||
perms | no | 递归选项的值 | yes no | 保留权限 |
recursive | no | 递归选项的值 | yes no | 递归到目录。 |
rsync_opts | no | 通过传入数组来指定其他rsync选项。 | ||
rsync_path | no | 指定要在远程主机上运行的rsync命令。请参见rsync手册页上的--rsync-path。 | ||
rsync_timeout | no | 以秒为单位指定rsync命令的--timeout。 | ||
set_remote_user | no | True | put user @为远程路径。如果您有自定义ssh配置为与库存用户不匹配的主机定义远程用户,则应将此参数设置为"no"。 | |
src | yes | 将同步到目标的源主机上的路径;路径可以是绝对路径或相对路径。 | ||
times | no | 递归选项的值 | yes no | 保存修改时间 |
use_ssh_args | no | no | yes no | 使用ansible.cfg中指定的ssh_args |
verify_host | no | 验证目标主机密钥。 |
1.同步目录下文件:
源文件:
# lltotal 4lrwxrwxrwx 1 root root 8 Dec 28 17:39 fk -> /data/fm-rw-r--r-- 1 root root 4096 May 31 2016 p.txt
同步目录下文件,而不是目录:
# ansible webserver -m synchronize -a "src=/root/dog/ dest=/tmp/"172.16.110.48 | SUCCESS => { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='<>%i %n%L' \"/root/dog/\" \"172.16.110.48:/tmp/\"", "msg": ".d..t...... ./\n", "rc": 0, "stdout_lines": [ ".d..t...... ./" ]}172.16.110.47 | SUCCESS => { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='< >%i %n%L' \"/root/dog/\" \"172.16.110.47:/tmp/\"", "msg": ".d..t...... ./\n", "rc": 0, "stdout_lines": [ ".d..t...... ./" ]}
同步了所有文件
# lltotal 8drwxr-xr-x 2 root root 29 Dec 28 17:39 doglrwxrwxrwx 1 root root 8 Dec 28 17:39 fk -> /data/fm //无效链接,源不存在
2.同步整个目录:
# ansible webserver -m synchronize -a "src=/root/dog dest=/tmp/" 172.16.110.48 | SUCCESS => { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='<>%i %n%L' \"/root/dog\" \"172.16.110.48:/tmp/\"", "msg": "cd+++++++++ dog/\ncL+++++++++ dog/fk -> /data/fm\n /data/fm", " { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='< >%i %n%L' \"/root/dog\" \"172.16.110.47:/tmp/\"", "msg": "cd+++++++++ dog/\ncL+++++++++ dog/fk -> /data/fm\n /data/fm", " 同步了整个目录
# lltotal 8drwxr-xr-x 2 root root 29 Dec 28 17:39 dog
3.同步时候保持属主,属组,权限,链接,同时传输的时候使用压缩
同步前文件详情:
# ll dog/total 8-rw-r--r-- 1 ckl ckl 9 Dec 29 13:05 em_flrwxrwxrwx 1 root root 8 Dec 28 17:39 fk -> /data/fm-rwx------ 1 root root 4096 May 31 2016 p.txt
同步:
# ansible webserver -m synchronize -a "compress=yes group=yes links=yes src=/root/dog/ dest=/tmp/sync_dir" 172.16.110.47 | SUCCESS => { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='<>%i %n%L' \"/root/dog/\" \"172.16.110.47:/tmp/sync_dir\"", "msg": ".d..t...... ./\n /data/fm\n /data/fm", " {"changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='< >%i %n%L' \"/root/dog/\" \"172.16.110.48:/tmp/sync_dir\"", "msg": ".d..t...... ./\n /data/fm\n /data/fm", " 结果:(权限及属性保持不变)
# lltotal 8-rw-r--r-- 1 ckl ckl 9 Dec 29 13:05 em_flrwxrwxrwx 1 root root 8 Dec 28 17:39 fk -> /data/fm //无效链接,源不存在-rwx------ 1 root root 4096 May 31 2016 p.txt
4.删除目标上的文件:
删除前文件:
# lltotal 8-rw-r--r-- 1 ckl ckl 9 Dec 29 13:05 em_flrwxrwxrwx 1 root root 8 Dec 28 17:39 fk -> /data/fm-rwx------ 1 root root 4096 May 31 2016 p.txt
删除:
# ansible webserver -m synchronize -a "src=/root/dele/ dest=/tmp/sync_dir delete=yes"172.16.110.47 | SUCCESS => { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --delete-after --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='<>%i %n%L' \"/root/dele/\" \"172.16.110.47:/tmp/sync_dir\"", "msg": "*deleting dele/\n*deleting p.txt\n*deleting fk\n*deleting em_f\n", "rc": 0, "stdout_lines": [ "*deleting dele/", "*deleting p.txt", "*deleting fk", "*deleting em_f" ]}172.16.110.48 | SUCCESS => { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --delete-after --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='< >%i %n%L' \"/root/dele/\" \"172.16.110.48:/tmp/sync_dir\"", "msg": "*deleting dele/\n*deleting p.txt\n*deleting fk\n*deleting em_f\n", "rc": 0, "stdout_lines": [ "*deleting dele/", "*deleting p.txt", "*deleting fk", "*deleting em_f" ]} 查看目标文件:
# ll /tmp/sync_dir/total 05.同步链接时,同步源文件
# lltotal 8-rw-r--r-- 1 ckl ckl 9 Dec 29 13:05 em_flrwxrwxrwx 1 root root 8 Dec 28 17:39 fk -> /data/fm-rwx------ 1 root root 4096 May 31 2016 p.txtdrwxr-xr-x 2 root root 20 Dec 29 13:15 wu[root@localhost dog]# ll *-rw-r--r-- 1 ckl ckl 9 Dec 29 13:05 em_flrwxrwxrwx 1 root root 8 Dec 28 17:39 fk -> /data/fm-rwx------ 1 root root 4096 May 31 2016 p.txtwu:total 4-rw-r--r-- 1 root root 14 Dec 29 13:15 kk.txt同步:
# ansible webserver -m synchronize -a "compress=yes group=yes copy_links=yes dirs=yes src=/root/dog/ dest=/tmp/sync_dir" 172.16.110.48 | SUCCESS => { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --copy-links --dirs --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='<>%i %n%L' \"/root/dog/\" \"172.16.110.48:/tmp/sync_dir\"", "msg": ".d..t...... ./\n { "changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --copy-links --dirs --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='< >%i %n%L' \"/root/dog/\" \"172.16.110.47:/tmp/sync_dir\"", "msg": ".d..t...... ./\n 查看结果:
# lltotal 12-rw-r--r-- 1 ckl ckl 9 Dec 29 13:05 em_f-rw-r--r-- 1 root root 7 Dec 28 16:49 fk //不再是链接-rwx------ 1 root root 4096 May 31 2016 p.txtdrwxr-xr-x 2 root root 20 Dec 29 13:15 wu
同步
文件
链接
递归
路径
主机
目录
目标
传输
参数
权限
符号
命令
库存
时候
时间
标志
模式
源文件
用户
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
如何破无线网络安全吗
什么是分布式数据库管理系统
刘家沟湾煤矿网络安全培训课
鹤壁电商财务软件开发
基因共表达数据库挖掘
科技互联网未来估值
搭建短信服务器
软件开发转工作
查询数据库日期数据
软件开发费用记入什么
春秋网络安全技能测试
数据库oracle的触发器
航海王启航服务器划分
java软件实现数据库远程备份
应用服务器主要功能
网络安全事件银行案例分析
广西来宾众森互联网科技
电力信息网络技术
新罗区旺油网络技术服务部
微型网站服务器的关键理论和技术
许继软件开发工程师待遇
戴尔服务器idrac控制风扇
软件开发转综合布线
绝地求生未来之翼服务器被搞崩了
svm 数据库
杭州边锋网络技术有限公
数据库字段扩展
河北通用软件开发近期价格
网络安全有什么保障措施
专硕没有网络安全么