ansible setup 模块,常用参数filter


文章目录

        • setup 模块

setup 模块

setup 模块用于收集远程主机的一些基本信息。常用参数 filter,使用 setup 常搜集的信息,这些 facts 信息可以直接以变量的形式使用,但是如果主机较多,会影响执行速度,可以使用 gather_facts: no 来禁止 Ansible 收集 facts 信息

filter=
        ansible_all_ipv4_addresses:             仅显示ipv4的信息。
        ansible_devices:                        仅显示磁盘设备信息。
        ansible_distribution:                   显示是什么系统,例:centos,suse等。
        ansible_distribution_major_version:     显示是系统主版本。
        ansible_distribution_version:           仅显示系统版本。
        ansible_machine:                        显示系统类型,例:32位,还是64位。
        ansible_eth0:                           仅显示eth0的信息。
        ansible_hostname:                       仅显示主机名。
        ansible_kernel:                         仅显示内核版本。
        ansible_lvm:                            显示lvm相关信息。
        ansible_memtotal_mb:                    显示系统总内存。
        ansible_memfree_mb:                     显示可用系统内存。
        ansible_memory_mb:                      详细显示内存情况。
        ansible_swaptotal_mb:                   显示总的swap内存。
        ansible_swapfree_mb:                    显示swap内存的可用内存。
        ansible_mounts:                         显示系统磁盘挂载情况。
        ansible_processor:                      显示cpu个数(具体显示每个cpu的型号)。
        ansible_processor_vcpus:                显示cpu个数(只显示总的个数)。
  • 搜集主机的所有系统信息
ansible 192.168.169.161 -m setup
192.168.169.161 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.169.161"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::7d00:28cc:f94f:a06a", 
            "fe80::ad67:cf07:7fc:c440"
        ], 
        "ansible_apparmor": {
            "status": "disabled"
        }, 
		........
  • 搜集系统信息并保存在指定目录,默认自动创建文件名,即为主机 ip 地址
[root@master ~]# ansible dong -m setup --tree /root/masterInfo
[root@master ~]# cd masterInfo/
[root@master masterInfo]# ls
192.168.169.161  192.168.169.162
或者直接使用
[root@master ~]# ansible dong -m setup > /root/masterInfo.txt

  • 搜集内存相关信息
[root@master ~]# ansible 192.168.169.161 -m setup -a "filter=ansible_*_mb"
192.168.169.161 | SUCCESS => {
    "ansible_facts": {
        "ansible_memfree_mb": 694, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 801, 
                "used": 175
            }, 
            "real": {
                "free": 694, 
                "total": 976, 
                "used": 282
            }, 
            "swap": {
                "cached": 0, 
                "free": 1023, 
                "total": 1023, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 976, 
        "ansible_swapfree_mb": 1023, 
        "ansible_swaptotal_mb": 1023, 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}

  • 查看主机内核
[root@master ~]# ansible dong -m setup -a "filter=ansible_kernel"
192.168.169.162 | SUCCESS => {
    "ansible_facts": {
        "ansible_kernel": "3.10.0-693.el7.x86_64", 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}
192.168.169.161 | SUCCESS => {
    "ansible_facts": {
        "ansible_kernel": "3.10.0-693.el7.x86_64", 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}

  • 搜集网卡信息
[root@master ~]# ansible 192.168.169.161 -m setup -a 'filter=ansible_ens*'
192.168.169.161 | SUCCESS => {
    "ansible_facts": {
        "ansible_ens33": {
            "active": true, 
            "device": "ens33", 
            "features": {
                "busy_poll": "off [fixed]", 
                "fcoe_mtu": "off [fixed]", 
                "generic_receive_offload": "on", 
                "generic_segmentation_offload": "on", 
                "highdma": "off [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", 
                "rx_checksumming": "off", 
                "rx_fcs": "off", 
                "rx_vlan_filter": "on [fixed]", 
                "rx_vlan_offload": "on", 
                "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_csum_segmentation": "off [fixed]", 
                "tx_gre_segmentation": "off [fixed]", 
                "tx_gso_partial": "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": "off [fixed]", 
                "tx_tcp_ecn_segmentation": "off [fixed]", 
                "tx_tcp_mangleid_segmentation": "off", 
                "tx_tcp_segmentation": "on", 
                "tx_udp_tnl_csum_segmentation": "off [fixed]", 
                "tx_udp_tnl_segmentation": "off [fixed]", 
                "tx_vlan_offload": "on [fixed]", 
                "tx_vlan_stag_hw_insert": "off [fixed]", 
                "udp_fragmentation_offload": "off [fixed]", 
                "vlan_challenged": "off [fixed]"
            }, 
            "hw_timestamp_filters": [], 
            "ipv4": {
                "address": "192.168.169.161", 
                "broadcast": "192.168.169.255", 
                "netmask": "255.255.255.0", 
                "network": "192.168.169.0"
            }, 
            "ipv6": [
                {
                    "address": "fe80::7d00:28cc:f94f:a06a", 
                    "prefix": "64", 
                    "scope": "link"
                }, 
                {
                    "address": "fe80::ad67:cf07:7fc:c440", 
                    "prefix": "64", 
                    "scope": "link"
                }
            ], 
            "macaddress": "00:0c:29:6d:e4:70", 
            "module": "e1000", 
            "mtu": 1500, 
            "pciid": "0000:02:01.0", 
            "promisc": false, 
            "speed": 1000, 
            "timestamping": [
                "tx_software", 
                "rx_software", 
                "software"
            ], 
            "type": "ether"
        }, 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}

 
 
 
 
 

相关内容