ansible组件——facts

facts组件是Ansible用于采集被管理机器设备信息的一个功能。
我们可以通过setup模块查看机器的所有facts信息,同时可以使用filter来查看指定信息。

执行ansible 127.0.0.1 -m setup:

148.70.122.28 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "172.17.0.1", 
            "172.27.16.8"
        ], 
        "ansible_all_ipv6_addresses": [], 
        "ansible_apparmor": {
            "status": "disabled"
        }, 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "01/01/2011", 
        "ansible_bios_version": "Bochs", 
        "ansible_cmdline": {
            "BOOT_IMAGE": "/boot/vmlinuz-3.10.0-514.26.2.el7.x86_64", 
            "LANG": "C", 
            "biosdevname": "0", 
            "console": "tty0", 
            "crashkernel": "auto", 
            "net.ifnames": "0", 
            "panic": "5", 
            "ro": true, 
            "root": "/dev/vda1"
        }, 
        "ansible_date_time": {
            "date": "2019-05-16", 
            "day": "16", 
            "epoch": "1558002342", 
            "hour": "18", 
            "iso8601": "2019-05-16T10:25:42Z", 
            "iso8601_basic": "20190516T182542937846", 
            "iso8601_basic_short": "20190516T182542", 
            "iso8601_micro": "2019-05-16T10:25:42.937975Z", 
            "minute": "25", 
            "month": "05", 
            "second": "42", 
            "time": "18:25:42", 
            "tz": "CST", 
            "tz_offset": "+0800", 
            "weekday": "Thursday", 
            "weekday_number": "4", 
            "weeknumber": "19", 
            "year": "2019"
        }, 
        "ansible_default_ipv4": {
            "address": "172.27.16.8", 
            "alias": "eth0", 
            "broadcast": "172.27.31.255", 
            "gateway": "172.27.16.1", 
            "interface": "eth0", 
            "macaddress": "52:54:00:99:f1:f6", 
            "mtu": 1500, 
            "netmask": "255.255.240.0", 
            "network": "172.27.16.0", 
            "type": "ether"
        }, 
        "ansible_default_ipv6": {}, 
        "ansible_device_links": {
            "ids": {
                "sr0": [
                    "ata-QEMU_DVD-ROM_QM00002"
                ]
            }, 
            "labels": {
                "sr0": [
                    "config-2"
                ]
            }, 
            "masters": {}, 
            "uuids": {
                "sr0": [
                    "2019-04-03-15-46-34-00"
                ], 
                "vda1": [
                    "49f819fd-e56d-48a4-86d3-7ebe0a68ec88"
                ]
            }
        }, 
        "ansible_devices": {
            "sr0": {
                "holders": [], 
                "host": "IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]", 
                "links": {
                    "ids": [
                        "ata-QEMU_DVD-ROM_QM00002"
                    ], 
                    "labels": [
                        "config-2"
                    ], 
                    "masters": [], 
                    "uuids": [
                        "2019-04-03-15-46-34-00"
                    ]
                }, 
                "model": "QEMU DVD-ROM", 
                "partitions": {}, 
                "removable": "1", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "cfq", 
                "sectors": "77128", 
                "sectorsize": "2048", 
                "size": "37.66 MB", 
                "support_discard": "0", 
                "vendor": "QEMU", 
                "virtual": 1
            }, 
            "vda": {
                "holders": [], 
                "host": "SCSI storage controller: Red Hat, Inc Virtio block device", 
                "links": {
                    "ids": [], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": []
                }, 
                "model": null, 
                "partitions": {
                    "vda1": {
                        "holders": [], 
                        "links": {
                            "ids": [], 
                            "labels": [], 
                            "masters": [], 
                            "uuids": [
                                "49f819fd-e56d-48a4-86d3-7ebe0a68ec88"
                            ]
                        }, 
                        "sectors": "104855552", 
                        "sectorsize": 512, 
                        "size": "50.00 GB", 
                        "start": "2048", 
                        "uuid": "49f819fd-e56d-48a4-86d3-7ebe0a68ec88"
                    }
                }, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "", 
                "sectors": "104857600", 
                "sectorsize": "512", 
                "size": "50.00 GB", 
                "support_discard": "0", 
                "vendor": "0x1af4", 
                "virtual": 1
            }
        }, 
        "ansible_distribution": "CentOS", 
        "ansible_distribution_file_parsed": true, 
        "ansible_distribution_file_path": "/etc/redhat-release", 
        "ansible_distribution_file_variety": "RedHat", 
        "ansible_distribution_major_version": "7", 
        "ansible_distribution_release": "Core", 
        "ansible_distribution_version": "7.2.1511", 
        "ansible_dns": {
            "nameservers": [
                "183.60.83.19", 
                "183.60.82.98"
            ]
        }, 
        "ansible_docker0": {
            "active": false, 
            "device": "docker0", 
            "features": {
                "busy_poll": "off [fixed]", 
                "fcoe_mtu": "off [fixed]", 
                "generic_receive_offload": "on", 
                "generic_segmentation_offload": "on", 
                "highdma": "on", 
                "hw_tc_offload": "off [fixed]", 
                "l2_fwd_offload": "off [fixed]", 
                "large_receive_offload": "off [fixed]", 
                "loopback": "off [fixed]", 
                "netns_local": "on [fixed]", 
                "ntuple_filters": "off [fixed]", 
                "receive_hashing": "off [fixed]", 
                "rx_all": "off [fixed]", 
                "rx_checksumming": "off [fixed]", 
                "rx_fcs": "off [fixed]", 
                "rx_vlan_filter": "off [fixed]", 
                "rx_vlan_offload": "off [fixed]", 
                "rx_vlan_stag_filter": "off [fixed]", 
                "rx_vlan_stag_hw_parse": "off [fixed]", 
                "scatter_gather": "on", 
                "tcp_segmentation_offload": "on", 
                "tx_checksum_fcoe_crc": "off [fixed]", 
                "tx_checksum_ip_generic": "on", 
                "tx_checksum_ipv4": "off [fixed]", 
                "tx_checksum_ipv6": "off [fixed]", 
                "tx_checksum_sctp": "off [fixed]", 
                "tx_checksumming": "on", 
                "tx_fcoe_segmentation": "on", 
                "tx_gre_segmentation": "on", 
                "tx_gso_robust": "on", 
                "tx_ipip_segmentation": "on", 
                "tx_lockless": "on [fixed]", 
                "tx_mpls_segmentation": "on", 
                "tx_nocache_copy": "off", 
                "tx_scatter_gather": "on", 
                "tx_scatter_gather_fraglist": "on", 
                "tx_sctp_segmentation": "on", 
                "tx_sit_segmentation": "on", 
                "tx_tcp6_segmentation": "on", 
                "tx_tcp_ecn_segmentation": "on", 
                "tx_tcp_segmentation": "on", 
                "tx_udp_tnl_segmentation": "on", 
                "tx_vlan_offload": "on", 
                "tx_vlan_stag_hw_insert": "off [fixed]", 
                "udp_fragmentation_offload": "on", 
                "vlan_challenged": "off [fixed]"
            }, 
            "hw_timestamp_filters": [], 
            "id": "8000.024299ffdab4", 
            "interfaces": [], 
            "ipv4": {
                "address": "172.17.0.1", 
                "broadcast": "global", 
                "netmask": "255.255.0.0", 
                "network": "172.17.0.0"
            }, 
            "macaddress": "02:42:99:ff:da:b4", 
            "mtu": 1500, 
            "promisc": false, 
            "stp": false, 
            "timestamping": [
                "rx_software", 
                "software"
            ], 
            "type": "bridge"
        }, 
        "ansible_domain": "", 
        "ansible_effective_group_id": 0, 
        "ansible_effective_user_id": 0, 
        "ansible_env": {
            "HISTSIZE": "3000", 
            "HISTTIMEFORMAT": "%F %T ", 
            "HOME": "/root", 
            "LANG": "en_US.utf8", 
            "LESSOPEN": "||/usr/bin/lesspipe.sh %s", 
            "LOGNAME": "root", 
            "MAIL": "/var/mail/root", 
            "PATH": "/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin", 
            "PROMPT_COMMAND": "history -a; ", 
            "PWD": "/root", 
            "QTDIR": "/usr/lib64/qt-3.3", 
            "QTINC": "/usr/lib64/qt-3.3/include", 
            "QTLIB": "/usr/lib64/qt-3.3/lib", 
            "QT_GRAPHICSSYSTEM": "native", 
            "QT_GRAPHICSSYSTEM_CHECKED": "1", 
            "SHELL": "/bin/bash", 
            "SHLVL": "2", 
            "SSH_CLIENT": "148.70.120.50 42014 22", 
            "SSH_CONNECTION": "148.70.120.50 42014 172.27.16.8 22", 
            "SSH_TTY": "/dev/pts/1", 
            "TERM": "xterm", 
            "USER": "root", 
            "XDG_RUNTIME_DIR": "/run/user/0", 
            "XDG_SESSION_ID": "63175", 
            "_": "/usr/bin/python"
        }, 
        "ansible_eth0": {
            "active": true, 
            "device": "eth0", 
            "features": {
                "busy_poll": "off [fixed]", 
                "fcoe_mtu": "off [fixed]", 
                "generic_receive_offload": "on", 
                "generic_segmentation_offload": "on", 
                "highdma": "on [fixed]", 
                "hw_tc_offload": "off [fixed]", 
                "l2_fwd_offload": "off [fixed]", 
                "large_receive_offload": "off [fixed]", 
                "loopback": "off [fixed]", 
                "netns_local": "off [fixed]", 
                "ntuple_filters": "off [fixed]", 
                "receive_hashing": "off [fixed]", 
                "rx_all": "off [fixed]", 
                "rx_checksumming": "on [fixed]", 
                "rx_fcs": "off [fixed]", 
                "rx_vlan_filter": "on [fixed]", 
                "rx_vlan_offload": "off [fixed]", 
                "rx_vlan_stag_filter": "off [fixed]", 
                "rx_vlan_stag_hw_parse": "off [fixed]", 
                "scatter_gather": "on", 
                "tcp_segmentation_offload": "on", 
                "tx_checksum_fcoe_crc": "off [fixed]", 
                "tx_checksum_ip_generic": "on", 
                "tx_checksum_ipv4": "off [fixed]", 
                "tx_checksum_ipv6": "off [fixed]", 
                "tx_checksum_sctp": "off [fixed]", 
                "tx_checksumming": "on", 
                "tx_fcoe_segmentation": "off [fixed]", 
                "tx_gre_segmentation": "off [fixed]", 
                "tx_gso_robust": "off [fixed]", 
                "tx_ipip_segmentation": "off [fixed]", 
                "tx_lockless": "off [fixed]", 
                "tx_mpls_segmentation": "off [fixed]", 
                "tx_nocache_copy": "off", 
                "tx_scatter_gather": "on", 
                "tx_scatter_gather_fraglist": "off [fixed]", 
                "tx_sctp_segmentation": "off [fixed]", 
                "tx_sit_segmentation": "off [fixed]", 
                "tx_tcp6_segmentation": "on", 
                "tx_tcp_ecn_segmentation": "on", 
                "tx_tcp_segmentation": "on", 
                "tx_udp_tnl_segmentation": "off [fixed]", 
                "tx_vlan_offload": "off [fixed]", 
                "tx_vlan_stag_hw_insert": "off [fixed]", 
                "udp_fragmentation_offload": "on", 
                "vlan_challenged": "off [fixed]"
            }, 
            "hw_timestamp_filters": [], 
            "ipv4": {
                "address": "172.27.16.8", 
                "broadcast": "172.27.31.255", 
                "netmask": "255.255.240.0", 
                "network": "172.27.16.0"
            }, 
            "macaddress": "52:54:00:99:f1:f6", 
            "module": "virtio_net", 
            "mtu": 1500, 
            "pciid": "virtio0", 
            "promisc": false, 
            "timestamping": [
                "rx_software", 
                "software"
            ], 
            "type": "ether"
        }, 
        "ansible_fips": false, 
        "ansible_form_factor": "Other", 
        "ansible_fqdn": "centos2", 
        "ansible_hostname": "centos2", 
        "ansible_interfaces": [
            "lo", 
            "docker0", 
            "eth0"
        ], 
        "ansible_is_chroot": false, 
        "ansible_iscsi_iqn": "", 
        "ansible_kernel": "3.10.0-514.26.2.el7.x86_64", 
        "ansible_lo": {
            "active": true, 
            "device": "lo", 
            "features": {
                "busy_poll": "off [fixed]", 
                "fcoe_mtu": "off [fixed]", 
                "generic_receive_offload": "on", 
                "generic_segmentation_offload": "on", 
                "highdma": "on [fixed]", 
                "hw_tc_offload": "off [fixed]", 
                "l2_fwd_offload": "off [fixed]", 
                "large_receive_offload": "off [fixed]", 
                "loopback": "on [fixed]", 
                "netns_local": "on [fixed]", 
                "ntuple_filters": "off [fixed]", 
                "receive_hashing": "off [fixed]", 
                "rx_all": "off [fixed]", 
                "rx_checksumming": "on [fixed]", 
                "rx_fcs": "off [fixed]", 
                "rx_vlan_filter": "off [fixed]", 
                "rx_vlan_offload": "off [fixed]", 
                "rx_vlan_stag_filter": "off [fixed]", 
                "rx_vlan_stag_hw_parse": "off [fixed]", 
                "scatter_gather": "on", 
                "tcp_segmentation_offload": "on", 
                "tx_checksum_fcoe_crc": "off [fixed]", 
                "tx_checksum_ip_generic": "on [fixed]", 
                "tx_checksum_ipv4": "off [fixed]", 
                "tx_checksum_ipv6": "off [fixed]", 
                "tx_checksum_sctp": "on [fixed]", 
                "tx_checksumming": "on", 
                "tx_fcoe_segmentation": "off [fixed]", 
                "tx_gre_segmentation": "off [fixed]", 
                "tx_gso_robust": "off [fixed]", 
                "tx_ipip_segmentation": "off [fixed]", 
                "tx_lockless": "on [fixed]", 
                "tx_mpls_segmentation": "off [fixed]", 
                "tx_nocache_copy": "off [fixed]", 
                "tx_scatter_gather": "on [fixed]", 
                "tx_scatter_gather_fraglist": "on [fixed]", 
                "tx_sctp_segmentation": "on", 
                "tx_sit_segmentation": "off [fixed]", 
                "tx_tcp6_segmentation": "on", 
                "tx_tcp_ecn_segmentation": "on", 
                "tx_tcp_segmentation": "on", 
                "tx_udp_tnl_segmentation": "off [fixed]", 
                "tx_vlan_offload": "off [fixed]", 
                "tx_vlan_stag_hw_insert": "off [fixed]", 
                "udp_fragmentation_offload": "on", 
                "vlan_challenged": "on [fixed]"
            }, 
            "hw_timestamp_filters": [], 
            "ipv4": {
                "address": "127.0.0.1", 
                "broadcast": "host", 
                "netmask": "255.0.0.0", 
                "network": "127.0.0.0"
            }, 
            "mtu": 65536, 
            "promisc": false, 
            "timestamping": [
                "rx_software", 
                "software"
            ], 
            "type": "loopback"
        }, 
        "ansible_local": {}, 
        "ansible_lsb": {
            "codename": "Core", 
            "description": "CentOS Linux release 7.2.1511 (Core)", 
            "id": "CentOS", 
            "major_release": "7", 
            "release": "7.2.1511"
        }, 
        "ansible_lvm": {
            "lvs": {}, 
            "pvs": {}, 
            "vgs": {}
        }, 
        "ansible_machine": "x86_64", 
        "ansible_machine_id": "f9d400c5e1e8c3a8209e990d887d4ac1", 
        "ansible_memfree_mb": 265, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 582, 
                "used": 410
            }, 
            "real": {
                "free": 265, 
                "total": 992, 
                "used": 727
            }, 
            "swap": {
                "cached": 0, 
                "free": 0, 
                "total": 0, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 992, 
        "ansible_mounts": [
            {
                "block_available": 10919769, 
                "block_size": 4096, 
                "block_total": 12868511, 
                "block_used": 1948742, 
                "device": "/dev/vda1", 
                "fstype": "ext3", 
                "inode_available": 3188297, 
                "inode_total": 3276800, 
                "inode_used": 88503, 
                "mount": "/", 
                "options": "rw,noatime,data=ordered", 
                "size_available": 44727373824, 
                "size_total": 52709421056, 
                "uuid": "49f819fd-e56d-48a4-86d3-7ebe0a68ec88"
            }, 
            {
                "block_available": 10919769, 
                "block_size": 4096, 
                "block_total": 12868511, 
                "block_used": 1948742, 
                "device": "/dev/vda1", 
                "fstype": "ext3", 
                "inode_available": 3188297, 
                "inode_total": 3276800, 
                "inode_used": 88503, 
                "mount": "/var/lib/docker/containers", 
                "options": "rw,noatime,data=ordered,bind", 
                "size_available": 44727373824, 
                "size_total": 52709421056, 
                "uuid": "49f819fd-e56d-48a4-86d3-7ebe0a68ec88"
            }, 
            {
                "block_available": 10919769, 
                "block_size": 4096, 
                "block_total": 12868511, 
                "block_used": 1948742, 
                "device": "/dev/vda1", 
                "fstype": "ext3", 
                "inode_available": 3188297, 
                "inode_total": 3276800, 
                "inode_used": 88503, 
                "mount": "/var/lib/docker/overlay2", 
                "options": "rw,noatime,data=ordered,bind", 
                "size_available": 44727373824, 
                "size_total": 52709421056, 
                "uuid": "49f819fd-e56d-48a4-86d3-7ebe0a68ec88"
            }
        ], 
        "ansible_nodename": "centos2", 
        "ansible_os_family": "RedHat", 
        "ansible_pkg_mgr": "yum", 
        "ansible_processor": [
            "0", 
            "GenuineIntel", 
            "Intel(R) Xeon(R) CPU E5-26xx v4"
        ], 
        "ansible_processor_cores": 1, 
        "ansible_processor_count": 1, 
        "ansible_processor_threads_per_core": 1, 
        "ansible_processor_vcpus": 1, 
        "ansible_product_name": "Bochs", 
        "ansible_product_serial": "d713599d-c127-4e85-b7ef-bc19a1de4096", 
        "ansible_product_uuid": "D713599D-C127-4E85-B7EF-BC19A1DE4096", 
        "ansible_product_version": "NA", 
        "ansible_python": {
            "executable": "/usr/bin/python", 
            "has_sslcontext": true, 
            "type": "CPython", 
            "version": {
                "major": 2, 
                "micro": 5, 
                "minor": 7, 
                "releaselevel": "final", 
                "serial": 0
            }, 
            "version_info": [
                2, 
                7, 
                5, 
                "final", 
                0
            ]
        }, 
        "ansible_python_version": "2.7.5", 
        "ansible_real_group_id": 0, 
        "ansible_real_user_id": 0, 
        "ansible_selinux": {
            "status": "disabled"
        }, 
        "ansible_selinux_python_present": true, 
        "ansible_service_mgr": "systemd", 
        "ansible_ssh_host_key_dsa_public": "AAAAB3NzaC1kc3MAAACBAKmxPxDGsfUC0aj7xhz8bE1yf7ARQz3hRH5LwYV62FnJx2M4nGieD7TRh31Q0wT1edYqD7DYNsU4+57OSNqlUMFvB65Svf9Yt6JJOc3vtlakCybyNrCwWbKLnEd98pXf7JKCOvG60GnfGIeOYgOfQPypfsKLJI3clnUpDcIbVxMZAAAAFQCzK9XuKJ79OYh+9BHmxblxxMyM1QAAAIBTThNEA+K+jrGhFerCFPbu8RcSSsEtssAMVOK/gx+aIiVzC1l+Px984Bto3OFcbn29XCeAPoxHd518cO1jw2CteLRnVHf/pNl1nl/mB8WsyHHAsK9xYJ77YZnuYG8G5C2n9gY2Plks7PXD4YFZ5kucpvC+BNpSygJSBD7SovZ/IwAAAIACBV9I+DSbWp9ZcNfHnjBnoIIze8B7OkGujfN9rvJO9MMvMmWBP64fvfrd+vht7Z1hlgVtN4tg+u+Ol2g98dVy/YFiA/l3e/RFy4AGCxx+VjbqGi/qNPxFwaIQcNgc4QA69N6TLUJeQxFfLaHVzlAoRW2ItTF3zR+0Qa2hKR/t9A==", 
        "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBH4O7LDyv61vyUYsu682pMqablZ6L3u+rL4dLORZYGCsz8nzlKs+x9zf4MzlDeV4e39t5xBlknWzQhGLjB44vGE=", 
        "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAILiS3/9yE2Fq3otdggxsYSrIdYysvNd+7K0QigiMnaOs", 
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQCtodyL+bKkUn7Ij0vW8Y3RkYgCdJ4bjvpeo2Efgzc5ih8kSjyyRCcgqPkVUtqW8C7xvpoiapWKQ3PidzB5JZD5CwuRmbxK0XmwrAkFTWx8onY7HZRPBx77dCcIvlyKBTxjqd1+b2UAB87YO/wpxGrcsM/0NVTEHiluX1rmqwOI2MVjjgSb1dcD9DbpD4kp0ebrH9NuCREoIr73gu2SDcTuWKweQqiUPezRB2NjDDpzvnHZLvcoJN7XJmmFHZ/yHX2qEgCWxBWWToG5DyaM4D3SDJChkq3xIXBckpEkM5Q1mjOpaOqLMO4UlP1EvbYYzgQIdzY6efv7xmmhOS2HKuG5", 
        "ansible_swapfree_mb": 0, 
        "ansible_swaptotal_mb": 0, 
        "ansible_system": "Linux", 
        "ansible_system_capabilities": [
            "cap_chown", 
            "cap_dac_override", 
            "cap_dac_read_search", 
            "cap_fowner", 
            "cap_fsetid", 
            "cap_kill", 
            "cap_setgid", 
            "cap_setuid", 
            "cap_setpcap", 
            "cap_linux_immutable", 
            "cap_net_bind_service", 
            "cap_net_broadcast", 
            "cap_net_admin", 
            "cap_net_raw", 
            "cap_ipc_lock", 
            "cap_ipc_owner", 
            "cap_sys_module", 
            "cap_sys_rawio", 
            "cap_sys_chroot", 
            "cap_sys_ptrace", 
            "cap_sys_pacct", 
            "cap_sys_admin", 
            "cap_sys_boot", 
            "cap_sys_nice", 
            "cap_sys_resource", 
            "cap_sys_time", 
            "cap_sys_tty_config", 
            "cap_mknod", 
            "cap_lease", 
            "cap_audit_write", 
            "cap_audit_control", 
            "cap_setfcap", 
            "cap_mac_override", 
            "cap_mac_admin", 
            "cap_syslog", 
            "35", 
            "36+ep"
        ], 
        "ansible_system_capabilities_enforced": "True", 
        "ansible_system_vendor": "Bochs", 
        "ansible_uptime_seconds": 3724739, 
        "ansible_user_dir": "/root", 
        "ansible_user_gecos": "root", 
        "ansible_user_gid": 0, 
        "ansible_user_id": "root", 
        "ansible_user_shell": "/bin/bash", 
        "ansible_user_uid": 0, 
        "ansible_userspace_architecture": "x86_64", 
        "ansible_userspace_bits": "64", 
        "ansible_virtualization_role": "guest", 
        "ansible_virtualization_type": "kvm", 
        "gather_subset": [
            "all"
        ], 
        "module_setup": true
    }, 
    "changed": false
}

使用filter来进行过滤:

 

posted @ 2020-04-07 21:53  明王不动心  阅读(530)  评论(0编辑  收藏  举报