码迷,mamicode.com
首页 > 其他好文 > 详细

ansible之synchronize模块

时间:2018-03-05 11:12:11      阅读:1686      评论:0      收藏:0      [点我收藏+]

标签:ansible之synchronize模

例:将主控方/root/test.yml 目录推送到指定节点的/tmp 目录下

[root@master ~]# ansible all -m synchronize -a ‘src=/tmp/test dest=/data/soft/ compress=yes‘

root@master.test.com‘s password: client02 | SUCCESS => {
    "changed": true, 
    "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh ‘ssh  -S none -o StrictHostKeyChecking=no‘ --out-format=‘<<CHANGED>>%i %n%L‘ \"/tmp/test\" \"client02:/data/soft/\"", 
    "msg": "<f+++++++++ test\n", 
    "rc": 0, 
    "stdout_lines": [
        "<f+++++++++ test"
    ]
}
client01 | SUCCESS => {
    "changed": true, 
    "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh ‘ssh  -S none -o StrictHostKeyChecking=no‘ --out-format=‘<<CHANGED>>%i %n%L‘ \"/tmp/test\" \"client01:/data/soft/\"", 
    "msg": "<f+++++++++ test\n", 
    "rc": 0, 
    "stdout_lines": [
        "<f+++++++++ test"
    ]
}

root@master.test.com‘s password: 111111此处输入密码原因是master自身没有做ssh免秘钥处理
master.test.com | SUCCESS => {
"changed": true,
"cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh ‘ssh -S none -o StrictHostKeyChecking=no‘ --out-format=‘<<CHANGED>>%i %n%L‘ \"/tmp/test\" \"master.test.com:/data/soft/\"",
"msg": "<f+++++++++ test\n",
"rc": 0,
"stdout_lines": [
"<f+++++++++ test"
]
}

[root@client02 ~]# ll /data/soft/test
-rw-r--r-- 1 root root 4 Jul 30 2016 /data/soft/test
}
[root@master tmp]# ll /data/soft/test
-rw-r--r-- 1 root root 4 Jul 30 23:31 /data/soft/test

执行效果:
delete=yes 使两边的内容一样(即以推送方为主)
compress=yes 开启压缩,默认为开启
--exclude=.git 忽略同步.git 结尾的文件
由于模块,默认都是推送push。因此,如果你在使用拉取pull 功能的时候,可以参考如下来实现mode=pull 更改推送模式为拉取模式

例:将client01 节点的/root/stu01 目录拉取到主控节点的/data/soft 目录下

[root@master tmp]# ansible client01 -m synchronize -a ‘mode=pull  src=/root/stu01 dest=/data/soft/ compress=yes‘
client01 | SUCCESS => {
    "changed": true, 
    "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh ‘ssh  -S none -o StrictHostKeyChecking=no‘ --out-format=‘<<CHANGED>>%i %n%L‘ \"client01:/root/stu01\" \"/data/soft/\"", 
    "msg": ">f+++++++++ stu01\n", 
    "rc": 0, 
    "stdout_lines": [
        ">f+++++++++ stu01"
    ]
}
[root@master tmp]# cat /data/soft/stu01 
213

参数解释
dest_port=22 指定目的主机的端口,ansible 配置文件中的
ansible_ssh_port 变量优先级高于该dest_port
变量
rsync_path 指定rsync 命令来在远程服务器上运行。这个参
考rsync 命令的--rsync-path 参数,
--rsync-path=PATH 指定远程服务器上的rsync 命令所在路径信息
rsync_timeout 指定rsync 操作的IP 超时时间,和rsync 命令
的--timeout 参数效果一样

ansible之synchronize模块

标签:ansible之synchronize模

原文地址:http://blog.51cto.com/wujianwei/2082905

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!