Ansible facts

facts組件是Ansible用於採集被管理機器設備信息的一個功能。可使用setup模塊查機器的全部facts信息,可使用filter來查看指定信息。整個facts信息被包裝在一個json格式的數據結構中,ansible_facts是最上層的值ios

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[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還支持查看指定信息,以下所示:json

1
2
3
4
5
6
7
8
9
10
[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
}
相關文章
相關標籤/搜索