Ansible facts

facts组件是Ansible用于采集被管理机器设备信息的一个功能。可以使用setup模块查机器的所有facts信息,可以使用filter来查看指定信息。整个facts信息被包装在一个json格式的数据结构中,ansible_facts是最上层的值

[root@LVS_Master playbook]# ansible 192.168.170.129 -m setup
192.168.170.129 | SUCCESS => {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.170.129",
"192.168.170.188"
],
"ansible_all_ipv6_addresses": [
"fe80::20c:29ff:fea0:6cd4"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "07/02/2015",
"ansible_bios_version": "6.00",
"ansible_cmdline": {
"KEYBOARDTYPE": "pc",
"KEYTABLE": "us",
"LANG": "zh_CN.UTF-8",
"quiet": true,
"rd_NO_DM": true,
"rd_NO_LUKS": true,
"rd_NO_LVM": true,
"rd_NO_MD": true,
"rhgb": true,
"ro": true,
"root": "UUID=b42623ce-7b8d-411c-bc1b-26ba53cfc4d8"
},
"ansible_date_time": {
"date": "2016-11-22",
"day": "22",
"epoch": "1479793846",
"hour": "13",
"iso8601": "2016-11-22T05:50:46Z",
"iso8601_basic": "20161122T135046459819",
"iso8601_basic_short": "20161122T135046",
"iso8601_micro": "2016-11-22T05:50:46.460213Z",
"minute": "50",
"month": "11",
"second": "46",
"time": "13:50:46",
"tz": "CST",
"tz_offset": "+0800",
"weekday": "星期二",
"weekday_number": "2",
"weeknumber": "47",
"year": "2016"
},
"ansible_default_ipv4": {
"address": "192.168.170.129",
"alias": "eth0",
"broadcast": "192.168.170.255",
"gateway": "192.168.170.2",
"interface": "eth0",
"macaddress": "00:0c:29:a0:6c:d4",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.170.0",
"type": "ether"
},
--------此处省略N行-------------------

所有数据格式都是JSON格式,facts还支持查看指定信息,如下所示:

[root@LVS_Master playbook]# ansible 192.168.170.129 -m setup -a 'filter=ansible_all_ipv4_addresses'
192.168.170.129 | SUCCESS => {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.170.129",
"192.168.170.188"
]
},
"changed": false
}
上一篇:Oracle pivot行转列函数案例


下一篇:Codeforces 570D - Tree Requests(树上启发式合并)