ansible模块--fetch模块
原创
©著作权归作者所有:来自51CTO博客作者wx62e28ac222a20的原创作品,请联系作者获取转载授权,否则将追究法律责任
fetch模块
将被控端得指定文件,拉取到Ansible服务器
src: 被控端源文件
dest: 主控端目录位置
1.拉取一个/tmp/test.txt 到ansible服务器端
[root@ansible tmp]# ansible mysql -m fetch -a 'src=/tmp/test.txt dest=/tmp'
192.168.56.88 | CHANGED => {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/tmp/192.168.56.88/tmp/test.txt",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"remote_md5sum": null
}
2.拉取被控端 以 .log结尾得所有文件。
由于 此模板只能拉取一个文件,所以将所有得log日志打包后,拉取到Ansible主控端
[root@ansible tmp]# ansible mysql -m shell -a 'tar -czvf /root/logs.tar.gz /var/log/*.log'
[WARNING]: Consider using the unarchive module rather than running 'tar'. If
you need to use command because unarchive is insufficient you can add 'warn:
false' to this command task or set 'command_warnings=False' in ansible.cfg to
get rid of this message.
192.168.56.88 | CHANGED | rc=0 >>
/var/log/boot.log
/var/log/yum.logtar: Removing leading `/' from member names
[root@ansible tmp]# ansible mysql -m fetch -a 'src=/root/logs.tar.gz dest=/tmp'
192.168.56.88 | CHANGED => {
"changed": true,
"checksum": "db8f8426b4f71add2c961eab80abb31c12d06da9",
"dest": "/tmp/192.168.56.88/root/logs.tar.gz",
"md5sum": "266b0bd1a882dda27488d2abc48092f4",
"remote_checksum": "db8f8426b4f71add2c961eab80abb31c12d06da9",
"remote_md5sum": null
}
[root@ansible tmp]# ll /tmp/192.168.56.88/root/logs.tar.gz
-rw-r--r-- 1 root root 144 Nov 14 11:26 /tmp/192.168.56.88/root/logs.tar.gz
版权声明:本文为博主原创文章,未经博主允许不得转载。
ansible