Ansible facts

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

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还支持查看指定信息,如下所示:

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
}
原文地址:https://www.cnblogs.com/davidshen/p/10593349.html