自动化运维—ansible常用模块之文件操作(fetch©模块)
文章目录
1.实验环境
首先配置好ansibel清单:
vim /etc/ansible/hosts
[testA]
server2
server3
[testB]
server4
[test:children]
testA
testB
2.模块管理
ansible-doc-l #列出ansible所支持的模块
ansible-doc -s fetch #查看模块的详细帮助信息(fetch模块)
ansible all -m ping #调用模块(调用ping模块)
3.fetch模块
fetch模块中参数作用:
- dest:指定拉取文件到本地以后,文件存放的位置
- src:指定从受管主机中拉取哪个文件
调用模块的同时传入参数:把testA组受管主机中的/etc/fstab拉取到本机的/testdir/ansible中
ansible testA -m fetch -a "src=/etc/fstab dest=/testdir/ansible"
查看到"changed": true,说明拉取成功(字体为黄色)
注意:/testdir/ansible目录原本并不存在
进入目录可以查看到拉取过来的文件:
再次拉取:
ansible testA -m fetch -a "src=/et