签到成功

知道了

CNDBA社区CNDBA社区

ansible模块--setup模块

2021-11-14 14:27 1085 0 原创 ansible
作者: hbhe0316

1.setup获取ipv4信息http://www.cndba.cn/hbhe0316/article/20744http://www.cndba.cn/hbhe0316/article/20744http://www.cndba.cn/hbhe0316/article/20744http://www.cndba.cn/hbhe0316/article/20744http://www.cndba.cn/hbhe0316/article/20744

[root@ansible ~]# ansible mysql -m setup -a "filter=ansible_all_ipv4_addresses"
192.168.56.88 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.56.88"
        ], 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}

2.获取内存信息http://www.cndba.cn/hbhe0316/article/20744

[root@ansible ~]# ansible mysql -m setup -a "filter=ansible_memory_mb"
192.168.56.88 | SUCCESS => {
    "ansible_facts": {
        "ansible_memory_mb": {
            "nocache": {
                "free": 7541, 
                "used": 440
            }, 
            "real": {
                "free": 7216, 
                "total": 7981, 
                "used": 765
            }, 
            "swap": {
                "cached": 0, 
                "free": 8063, 
                "total": 8063, 
                "used": 0
            }
        }, 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}

3.通过通配符实现模糊匹配,比如以”mb”关键字结尾的信息。http://www.cndba.cn/hbhe0316/article/20744

http://www.cndba.cn/hbhe0316/article/20744

[root@ansible ~]# ansible mysql -m setup -a "filter=*mb"
192.168.56.88 | SUCCESS => {
    "ansible_facts": {
        "ansible_memfree_mb": 7218, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 7543, 
                "used": 438
            }, 
            "real": {
                "free": 7218, 
                "total": 7981, 
                "used": 763
            }, 
            "swap": {
                "cached": 0, 
                "free": 8063, 
                "total": 8063, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 7981, 
        "ansible_swapfree_mb": 8063, 
        "ansible_swaptotal_mb": 8063, 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}

4.获取CPU信息http://www.cndba.cn/hbhe0316/article/20744

[root@ansible ~]# ansible mysql -m setup -a "filter=ansible_processor_vcpus"
192.168.56.88 | SUCCESS => {
    "ansible_facts": {
        "ansible_processor_vcpus": 10, 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}

5.filter的各种http://www.cndba.cn/hbhe0316/article/20744

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

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
hbhe0316

hbhe0316

关注

1.只有承认无知,才能装下新的东西; 2.进步来自一点点滴滴的积累; 3.广博让你更优秀,而专业让你无法替代; 4.挫折和失败能够转换为一种财富。

  • 889
    原创
  • 1
    翻译
  • 13
    转载
  • 24
    评论
  • 访问:1039003次
  • 积分:1523
  • 等级:核心会员
  • 排名:第6名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ