Ansible 获取主机信息模块setup、获取文件详细信息模块
2018-03-26 本文已影响16人
SkTj
setup
1、获取setup的所有信息,获取的信息有上百条:
ansible all -m setup
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"172.xx.xx.xxx"
],
"ansible_all_ipv6_addresses": [
"fe80::250:56ff:febc:5e1d"
],
..........................................
..........................................
"module_setup": true
},
"changed": false
}
2、对查询的结果进行筛选:
ansible all -m setup -a 'filter=ansible_*_mb'
![](https://img.haomeiwen.com/i9967595/f0f7b812d9348eed.png)
3、将每台主机的信息,分别存放到特定目录中,文件名为hosts文件中对应的别名或IP:
ansible all -m setup --tree /tmp/facts
![](https://img.haomeiwen.com/i9967595/f12103735c3d0bd7.png)
stat
4、获取文件的详细信息:
ansible all -m stat -a "path=/root/test.sh"
![](https://img.haomeiwen.com/i9967595/4d984567caa63931.png)