【自动化运维系列教程】Ansible自动化运维工具

一、关于Ansible

基于python语言开发,自动化运维工具
实现IT基础设施设备进行批量管控

1.Ansible的特性

  • 开源的、跨平台的
  • 底层基于ssh协议通信的
  • no server
  • no agent
  • 支持playbook剧本
  • 提供API接口

二、部署Ansible

1.关闭防火墙和SElinux、配置时间同步

过程省略

2.配置yum源和epel

[root@zabbix_server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@zabbix_server ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@zabbix_server ~]# yum clean all && yum makecache fast

3.配置ssh免密

[root@zabbix_server ~]# ssh-keygen -t rsa
[root@zabbix_server ~]# ssh-copy-id [email protected]
[root@zabbix_server ~]# ssh-copy-id [email protected]

4.在管理机上安装Ansible

A.安装Ansible

[root@zabbix_server ~]# yum install -y ansible

B.查看Ansible配置文件和版本信息

[root@zabbix_server ~]# ansible --version
ansible 2.9.27		#版本信息
  config file = /etc/ansible/ansible.cfg		#当前正在使用的配置文件具体位置
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

C.配置子配置文件和连接信息

创建Ansible用到的目录
[root@zabbix_server ~]# mkdir /root/ansible
复制配置文件
[root@zabbix_server ~]# cp /etc/ansible/ansible.cfg /root/ansible/
建立连接信息
[root@zabbix_server ~]#  cd ./ansible
[root@zabbix_server ansible]# ansible --version
ansible 2.9.27
  config file = /root/ansible/ansible.cfg		#这里配置文件目录为当前目录下
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
修改子配置文件
[root@zabbix_server ansible]# vim /root/ansible/ansible.cfg
inventory= /root/ansible/hosts		#指定清单路径
remote_user= root		#指定远程用户为root
host_key_checking= false		#免除远程yes操作

D.连接客户机

修改hosts文件
[root@zabbix_server ansible]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.140.10 server.example.com server	#添加服务器 IP地址请更换你的
192.168.140.11 node1.example.com node1	#添加客户机 IP地址请更换你的
192.168.140.12 node2.example.com node2
192.168.140.13 node3.example.com node3
拷贝配置文件给客户机
[root@zabbix_server ansible]# scp /etc/hosts [email protected]:/etc/hosts
[root@zabbix_server ansible]# scp /etc/hosts [email protected]:/etc/hosts
[root@zabbix_server ansible]# scp /etc/hosts [email protected]:/etc/hosts

E.测试

在当前目录下创建一个清单文件
[root@zabbix_server ansible]# vim /root/ansible/hosts

[webserver]
node1
node2

[dbserver]
node3

[all:vars]
ansible_password=centos
测试
[root@master01 ansible]# ansible webserver -m shell -a 'hostname'
node1 | CHANGED | rc=0 >>
node1
node2 | CHANGED | rc=0 >>
node2

三、Ansible AD HOC

  • 调用模块

1.Ansible命令格式

# ansible <被管理机> -m <模块名称> [-a <模块参数>]

被管理机的写法

  • all所有主机
    • [root@zabbix_server ~]# ansible all -m ping
  • 单个主机
    • [root@zabbix_server ~]# ansible 192.168.140.11 -m ping
  • 主机组名
    • [root@zabbix_server ~]# ansible dbserver -m ping
  • 多个主机组
    • [root@zabbix_server ~]# ansible 'appserver:!dbserver' -m ping
      • 差集
    • [root@zabbix_server ~]# ansible 'appserver:dbserver' -m ping
      • 并集
    • [root@zabbix_server ~]# ansible 'appserver:&dbserver' -m ping
      • 交集

2.关于模块帮助

[root@master01 ansible]# ansible-doc 模块名称

四、Ansible常用模块

1.ping模块

测试通信

[root@zabbix_server ~]# ansible webserver -m ping
node1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
node2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

2.shell模块

  • 在被管理机上统一执行shell命令
  • 参数
    • chdir=目录名称
[root@zabbix_server ~]# ansible webserver -m shell -a 'uptime'
node1 | CHANGED | rc=0 >>
 15:57:44 up  6:16,  2 users,  load average: 0.00, 0.01, 0.05
node2 | CHANGED | rc=0 >>
 15:57:44 up  6:33,  3 users,  load average: 0.00, 0.01, 0.05
[root@zabbix_server ~]# ansible webserver -m shell -a 'chdir=/tmp ls -l'
node2 | CHANGED | rc=0 >>
总用量 0
drwx------ 2 root root 41 5月  15 10:00 ansible_command_payload_5zsIa2
drwx------ 2 root root 41 5月  15 10:00 ansible_command_payload_atZfHF
drwx------ 2 root root 41 5月  15 15:58 ansible_command_payload_NwfW4b
drwx------ 3 root root 17 3月  17 18:42 systemd-private-48a786b208c54b83b538dca3f1ce661b-chronyd.service-Tn7iUG
drwx------ 2 root root  6 5月  15 09:47 vmware-root_648-2688619569
node1 | CHANGED | rc=0 >>
总用量 0
drwx------ 2 root root 41 5月  15 10:00 ansible_command_payload_G2bPre
drwx------ 2 root root 41 5月  15 15:58 ansible_command_payload_XYZghL
drwx------ 2 root root 41 5月  15 10:00 ansible_command_payload_yB62n0
drwx------ 3 root root 17 4月  25 14:05 systemd-private-1e71f30e2c1d45379b48a56d28de1db3-chronyd.service-tB2KfM

3.copy模块

  • 推送文件
  • 常用参数:
    • src=源文件
    • dest=目的文件
    • mode=权限
    • owner=属主
    • group=属组
[root@zabbix_server ~]# ansible webserver -m copy -a 'src=/etc/hosts dest=/tmp'

node2 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "599bcb4c95ad1e9d53603eea627fd2f479e948cd", 
    "dest": "/tmp/hosts", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "1047c02d8443a9e7e464d10bf2bd9079", 
    "mode": "0644", 
    "owner": "root", 
    "size": 308, 
    "src": "/root/.ansible/tmp/ansible-tmp-1684137792.29-5003-272837908617971/source", 
    "state": "file", 
    "uid": 0
}
node1 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "599bcb4c95ad1e9d53603eea627fd2f479e948cd", 
    "dest": "/tmp/hosts", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "1047c02d8443a9e7e464d10bf2bd9079", 
    "mode": "0644", 
    "owner": "root", 
    "size": 308, 
    "src": "/root/.ansible/tmp/ansible-tmp-1684137792.3-5002-165795823996149/source", 
    "state": "file", 
    "uid": 0
}
[root@zabbix_server ~]# ansible webserver -m copy -a 'src=/opt/file02.txt dest=/tmp mode=0600 owner=nobody group=nobody'

node2 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "a8d256841c0d7f59f039d47d2de630af6d9a0f34", 
    "dest": "/tmp/fstab", 
    "gid": 1000, 
    "group": "student", 
    "md5sum": "3ea4524e044adad46cd00afddb7d02d9", 
    "mode": "0600", 
    "owner": "student", 
    "size": 465, 
    "src": "/root/.ansible/tmp/ansible-tmp-1684138025.01-5117-280877163462644/source", 
    "state": "file", 
    "uid": 1000
}
node1 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "a8d256841c0d7f59f039d47d2de630af6d9a0f34", 
    "dest": "/tmp/fstab", 
    "gid": 1000, 
    "group": "student", 
    "md5sum": "3ea4524e044adad46cd00afddb7d02d9", 
    "mode": "0600", 
    "owner": "student", 
    "size": 465, 
    "src": "/root/.ansible/tmp/ansible-tmp-1684138025.02-5116-74769411422857/source", 
    "state": "file", 
    "uid": 1000
}

4.fetch模块

  • 从被管理机拉取文件
  • 常用参数:
    • src=源文件
    • dest=目的文件
[root@ansible ~]# ansible webserver -m fetch -a 'src=/tmp/test01 dest=/tmp'

5.file模块

  • 管理服务器文件目录
  • 常用参数:
    • path=指定文件、目录名称
    • owner=指明文件的属主
    • group=指明文件的属组
    • mode=指明文件的权限
    • state=directory创建目录
    • state=link创建软链接文件
    • state=absent删除文件
    • state=touch创建文件
    • src=指定软链接的原文件,配合state=link时有用
[root@ansible ~]# ansible webserver -m file -a 'path=/tmp/file02.txt mode=0666 owner=root group=root'
[root@ansible ~]# ansible webserver -m file -a 'path=/tmp/nginx state=directory'

6.cron模块

  • 管理周期性计划任务
  • 常用参数:
    • minute=指明计划任务的分钟,支持格式:0-59
    • hour=指明计划任务的小时,支持的语法:0-23
    • day=指明计划任务的天,支持的语法:1-31
    • month=指明计划任务的月,支持的语法为:1-12
    • weekday=指明计划任务的星期几,支持的语法为:0-6
    • name=给该计划任务取个名称,必须要给明。每个任务的名称不能一样。
    • job=执行的任务是什么
    • state=present|absent
      • present创建
      • absent删除
[root@ansible ~]# ansible webserver -m cron -a 'name=TimeSync minute=*/30 job="/usr/sbin/ntpdate  120.25.115.20 &> /dev/null" state=present'

7.yum模块

  • 管理RPM软件
  • 常用参数
    • name=软件名称
    • state={present|absent|latest}
      • present启动
      • absent关闭
      • latest最新版
    • enablerepo=启用yum仓库
    • disablerepo=禁用yum仓库
[root@ansible ~]# ansible webserver -m yum -a 'name=vsftpd state=present'

8.service模块

  • 管理系统服务
  • 常用参数
    • name=服务名称
    • state={started|restarted|stopped}
      • started启动
      • restarted重启
      • stopped关闭
    • enabled={yes|no}
      • yes开机自启动
      • no开机不启动
[root@ansible ~]# ansible webserver -m service -a 'name=vsftpd state=started enabled=yes'
[root@ansible ~]# ansible webserver -m service -a 'name=vsftpd state=stopped'

9.group模块

  • 管理用户组
  • 常用参数:
    • name=被管理的组名
    • state=present|absent
      • present添加组
      • absent删除组
    • gid=指明GID
    • system=yes|no是否为系统组
[root@ansible ~]# ansible webserver -m group -a 'name=jishu state=present'

10.user模块

  • 管理用户
  • 常用参数
    • name=指明要管理的账号名称
    • state=present|absent
      • present表示创建,absent表示删除
    • system=yes|no指明是否为系统账号
    • uid=指明用户UID
    • group=指明用户的基本组
    • groups=指明用户的附加组
    • shell=指明默认的shell
    • home=指明用户的家目录
    • password=指明用户的密码,最好使用加密好的字符
    • comment=指明用户的注释信息
    • remove=yes|nostate=absent时,也就是删除用户时,是否要删除用户的家目录
[root@ansible ~]# ansible webserver -m user -a 'name=king groups=jishu shell=/sbin/nologin state=present'

11.script模块

  • 推送脚本、自动执行脚本
  • 常用参数:
    • 脚本名称
[root@ansible ~]# ansible webserver -m script -a '/root/test.sh'

12.lineinfile模块

  • 管理文件内容
[root@ansible ~]# ansible webserver -m lineinfile -a 'path=/etc/hosts line="10.1.1.1 agent01.linux.com"'

13.setup模块(重要)

  • 后续的剧本中,会用到这里面的变量
  • 搜集被管理机的状态信息(IP地址、主机名、系统版本、内存大小、CPU型号等),统称facts变量
[root@master01 ansible]# ansible node1 -m setup 

node1 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.140.11"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::20c:29ff:fe37:97c7"
        ], 
        "ansible_apparmor": {
            "status": "disabled"
        }, 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "11/12/2020", 
        "ansible_bios_version": "6.00", 
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-1160.el7.x86_64", 
            "LANG": "zh_CN.UTF-8", 
            "crashkernel": "auto", 
            "quiet": true, 
            "rd.lvm.lv": "centos/swap", 
            "rhgb": true, 
            "ro": true, 
            "root": "/dev/mapper/centos-root"
        }, 
        "ansible_date_time": {
            "date": "2023-05-15", 
            "day": "15", 
            "epoch": "1684142821", 
            "hour": "17", 
            "iso8601": "2023-05-15T09:27:01Z", 
            "iso8601_basic": "20230515T172701434185", 
            "iso8601_basic_short": "20230515T172701", 
            "iso8601_micro": "2023-05-15T09:27:01.434185Z", 
            "minute": "27", 
            "month": "05", 
            "second": "01", 
            "time": "17:27:01", 
            "tz": "CST", 
            "tz_offset": "+0800", 
            "weekday": "星期一", 
            "weekday_number": "1", 
            "weeknumber": "20", 
            "year": "2023"
        }, 
        "ansible_default_ipv4": {
            "address": "192.168.140.11", 
            "alias": "ens33", 
            "broadcast": "192.168.140.255", 
            "gateway": "192.168.140.2", 
            "interface": "ens33", 
            "macaddress": "00:0c:29:37:97:c7", 
            "mtu": 1500, 
            "netmask": "255.255.255.0", 
            "network": "192.168.140.0", 
            "type": "ether"
        }, 
        "ansible_default_ipv6": {}, 
        "ansible_device_links": {
            "ids": {
                "dm-0": [
                    "dm-name-centos-root", 
                    "dm-uuid-LVM-OLO7GRb67emHfncffRG1XyiYndhJZ4vj1E07jNy6r1SU11s7MIufjbRxpcUPaBco"
                ], 
                "dm-1": [
                    "dm-name-centos-swap", 
                    "dm-uuid-LVM-OLO7GRb67emHfncffRG1XyiYndhJZ4vjnCZ7d33q36i8rG3z6iYmInKuOP8SlbGi"
                ], 
                "sda2": [
                    "lvm-pv-uuid-8dIHWy-Qxyv-0dZp-bl52-O9s2-4L3q-92KSds"
                ], 
                "sr0": [
                    "ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001"
                ]
            }, 
            "labels": {}, 
            "masters": {
                "sda2": [
                    "dm-0", 
                    "dm-1"
                ]
            }, 
            "uuids": {
                "dm-0": [
                    "39ad21bb-f420-4236-9343-e4c8ad32aefd"
                ], 
                "dm-1": [
                    "0f2f0244-ae9a-4224-bf65-05518c7210b9"
                ], 
                "sda1": [
                    "13d01e00-1f54-4718-bc51-041c787cf659"
                ]
            }
        }, 
        "ansible_devices": {
            "dm-0": {
                "holders": [], 
                "host": "", 
                "links": {
                    "ids": [
                        "dm-name-centos-root", 
                        "dm-uuid-LVM-OLO7GRb67emHfncffRG1XyiYndhJZ4vj1E07jNy6r1SU11s7MIufjbRxpcUPaBco"
                    ], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": [
                        "39ad21bb-f420-4236-9343-e4c8ad32aefd"
                    ]
                }, 
                "model": null, 
                "partitions": {}, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "", 
                "sectors": "36716544", 
                "sectorsize": "512", 
                "size": "17.51 GB", 
                "support_discard": "0", 
                "vendor": null, 
                "virtual": 1
            }, 
            "dm-1": {
                "holders": [], 
                "host": "", 
                "links": {
                    "ids": [
                        "dm-name-centos-swap", 
                        "dm-uuid-LVM-OLO7GRb67emHfncffRG1XyiYndhJZ4vjnCZ7d33q36i8rG3z6iYmInKuOP8SlbGi"
                    ], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": [
                        "0f2f0244-ae9a-4224-bf65-05518c7210b9"
                    ]
                }, 
                "model": null, 
                "partitions": {}, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "", 
                "sectors": "4194304", 
                "sectorsize": "512", 
                "size": "2.00 GB", 
                "support_discard": "0", 
                "vendor": null, 
                "virtual": 1
            }, 
            "sda": {
                "holders": [], 
                "host": "SCSI storage controller: Broadcom / LSI 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)", 
                "links": {
                    "ids": [], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": []
                }, 
                "model": "VMware Virtual S", 
                "partitions": {
                    "sda1": {
                        "holders": [], 
                        "links": {
                            "ids": [], 
                            "labels": [], 
                            "masters": [], 
                            "uuids": [
                                "13d01e00-1f54-4718-bc51-041c787cf659"
                            ]
                        }, 
                        "sectors": "1024000", 
                        "sectorsize": 512, 
                        "size": "500.00 MB", 
                        "start": "2048", 
                        "uuid": "13d01e00-1f54-4718-bc51-041c787cf659"
                    }, 
                    "sda2": {
                        "holders": [
                            "centos-root", 
                            "centos-swap"
                        ], 
                        "links": {
                            "ids": [
                                "lvm-pv-uuid-8dIHWy-Qxyv-0dZp-bl52-O9s2-4L3q-92KSds"
                            ], 
                            "labels": [], 
                            "masters": [
                                "dm-0", 
                                "dm-1"
                            ], 
                            "uuids": []
                        }, 
                        "sectors": "40916992", 
                        "sectorsize": 512, 
                        "size": "19.51 GB", 
                        "start": "1026048", 
                        "uuid": null
                    }
                }, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "deadline", 
                "sectors": "41943040", 
                "sectorsize": "512", 
                "size": "20.00 GB", 
                "support_discard": "0", 
                "vendor": "VMware,", 
                "virtual": 1
            }, 
            "sr0": {
                "holders": [], 
                "host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)", 
                "links": {
                    "ids": [
                        "ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001"
                    ], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": []
                }, 
                "model": "VMware IDE CDR10", 
                "partitions": {}, 
                "removable": "1", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "deadline", 
                "sectors": "2097151", 
                "sectorsize": "512", 
                "size": "1024.00 MB", 
                "support_discard": "0", 
                "vendor": "NECVMWar", 
                "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.9", 
        "ansible_dns": {
            "nameservers": [
                "114.114.114.114", 
                "8.8.8.8"
            ]
        }, 
        "ansible_domain": "linux.com", 
        "ansible_effective_group_id": 0, 
        "ansible_effective_user_id": 0, 
        "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_gro_hw": "off [fixed]", 
                "rx_udp_tunnel_port_offload": "off [fixed]", 
                "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_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.140.11", 
                "broadcast": "192.168.140.255", 
                "netmask": "255.255.255.0", 
                "network": "192.168.140.0"
            }, 
            "ipv6": [
                {
                    "address": "fe80::20c:29ff:fe37:97c7", 
                    "prefix": "64", 
                    "scope": "link"
                }
            ], 
            "macaddress": "00:0c:29:37:97:c7", 
            "module": "e1000", 
            "mtu": 1500, 
            "pciid": "0000:02:01.0", 
            "promisc": false, 
            "speed": 1000, 
            "timestamping": [
                "tx_software", 
                "rx_software", 
                "software"
            ], 
            "type": "ether"
        }, 
        "ansible_env": {
            "HOME": "/root", 
            "LANG": "zh_CN.UTF-8", 
            "LESSOPEN": "||/usr/bin/lesspipe.sh %s", 
            "LOGNAME": "root", 
            "LS_COLORS": "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:", 
            "MAIL": "/var/mail/root", 
            "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin", 
            "PWD": "/root", 
            "SHELL": "/bin/bash", 
            "SHLVL": "2", 
            "SSH_CLIENT": "192.168.140.10 48140 22", 
            "SSH_CONNECTION": "192.168.140.10 48140 192.168.140.11 22", 
            "SSH_TTY": "/dev/pts/0", 
            "TERM": "xterm", 
            "USER": "root", 
            "XDG_RUNTIME_DIR": "/run/user/0", 
            "XDG_SESSION_ID": "27", 
            "_": "/usr/bin/python"
        }, 
        "ansible_fibre_channel_wwn": [], 
        "ansible_fips": false, 
        "ansible_form_factor": "Other", 
        "ansible_fqdn": "node1.linux.com", 
        "ansible_hostname": "node1", 
        "ansible_hostnqn": "", 
        "ansible_interfaces": [
            "lo", 
            "ens33"
        ], 
        "ansible_is_chroot": false, 
        "ansible_iscsi_iqn": "", 
        "ansible_kernel": "3.10.0-1160.el7.x86_64", 
        "ansible_kernel_version": "#1 SMP Mon Oct 19 16:18:59 UTC 2020", 
        "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_gro_hw": "off [fixed]", 
                "rx_udp_tunnel_port_offload": "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_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": "on [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_mangleid_segmentation": "on", 
                "tx_tcp_segmentation": "on", 
                "tx_udp_tnl_csum_segmentation": "off [fixed]", 
                "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": "", 
                "netmask": "255.0.0.0", 
                "network": "127.0.0.0"
            }, 
            "ipv6": [
                {
                    "address": "::1", 
                    "prefix": "128", 
                    "scope": "host"
                }
            ], 
            "mtu": 65536, 
            "promisc": false, 
            "timestamping": [
                "rx_software", 
                "software"
            ], 
            "type": "loopback"
        }, 
        "ansible_local": {}, 
        "ansible_lsb": {}, 
        "ansible_lvm": {
            "lvs": {
                "root": {
                    "size_g": "17.51", 
                    "vg": "centos"
                }, 
                "swap": {
                    "size_g": "2.00", 
                    "vg": "centos"
                }
            }, 
            "pvs": {
                "/dev/sda2": {
                    "free_g": "0", 
                    "size_g": "19.51", 
                    "vg": "centos"
                }
            }, 
            "vgs": {
                "centos": {
                    "free_g": "0", 
                    "num_lvs": "2", 
                    "num_pvs": "1", 
                    "size_g": "19.51"
                }
            }
        }, 
        "ansible_machine": "x86_64", 
        "ansible_machine_id": "8dece1781ceb4ea4b1000cdd617091f2", 
        "ansible_memfree_mb": 1471, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 1606, 
                "used": 213
            }, 
            "real": {
                "free": 1471, 
                "total": 1819, 
                "used": 348
            }, 
            "swap": {
                "cached": 0, 
                "free": 2047, 
                "total": 2047, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 1819, 
        "ansible_mounts": [
            {
                "block_available": 90521, 
                "block_size": 4096, 
                "block_total": 127145, 
                "block_used": 36624, 
                "device": "/dev/sda1", 
                "fstype": "xfs", 
                "inode_available": 255673, 
                "inode_total": 256000, 
                "inode_used": 327, 
                "mount": "/boot", 
                "options": "rw,relatime,attr2,inode64,noquota", 
                "size_available": 370774016, 
                "size_total": 520785920, 
                "uuid": "13d01e00-1f54-4718-bc51-041c787cf659"
            }, 
            {
                "block_available": 4100956, 
                "block_size": 4096, 
                "block_total": 4587008, 
                "block_used": 486052, 
                "device": "/dev/mapper/centos-root", 
                "fstype": "xfs", 
                "inode_available": 9146425, 
                "inode_total": 9179136, 
                "inode_used": 32711, 
                "mount": "/", 
                "options": "rw,relatime,attr2,inode64,noquota", 
                "size_available": 16797515776, 
                "size_total": 18788384768, 
                "uuid": "39ad21bb-f420-4236-9343-e4c8ad32aefd"
            }
        ], 
        "ansible_nodename": "node1", 
        "ansible_os_family": "RedHat", 
        "ansible_pkg_mgr": "yum", 
        "ansible_proc_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-1160.el7.x86_64", 
            "LANG": "zh_CN.UTF-8", 
            "crashkernel": "auto", 
            "quiet": true, 
            "rd.lvm.lv": [
                "centos/root", 
                "centos/swap"
            ], 
            "rhgb": true, 
            "ro": true, 
            "root": "/dev/mapper/centos-root"
        }, 
        "ansible_processor": [
            "0", 
            "GenuineIntel", 
            "Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz"
        ], 
        "ansible_processor_cores": 1, 
        "ansible_processor_count": 1, 
        "ansible_processor_threads_per_core": 1, 
        "ansible_processor_vcpus": 1, 
        "ansible_product_name": "VMware Virtual Platform", 
        "ansible_product_serial": "VMware-56 4d 91 cd 00 dd 97 a0-86 19 17 7a cc 37 97 c7", 
        "ansible_product_uuid": "CD914D56-DD00-A097-8619-177ACC3797C7", 
        "ansible_product_version": "None", 
        "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_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEJRIK+wptQ36VVPvCLAb/DDkXYC45D+u1lUZrLbp/uUd554tlbGK1AuXeJ/PZ/5GXF/tg0BKCKEBPaF+sIwMxs=", 
        "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAIGRbSN3tNIuTVhZM06Xm3kfxtYmlhCECY+pIfDqmlUob", 
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDQpua6HTb+PhJn/KFHkoZQdJOsfk8iTtVclSEhEAJHFDilxkghvnR2ErYsVmrTXf7EoKwU6S6I/w6QRg3fk2GP6Z4r6o3uO76Cx1rkDC+nf5tQnGIHSgDYxyk3ASVgK0GgSISJVWZr8Okm7gO2sOzQ4VSnuORJ5z0x2bIqobsEIMN+FvfOh7hWSEgAenF3pIP1rpwd+6ADNwo2CALSqi9x7wJ9ClC96ym8X52byL1Eg1ANP7wQ7n+jswLIGJWOoBgXL2w17OMY3AmpLzyvyonl0kb3WKs5boqTmM1TTMvrHD2FOw/NRSVbBfse/3/13Jb5HDXvVLss6qctyfbTCzqd", 
        "ansible_swapfree_mb": 2047, 
        "ansible_swaptotal_mb": 2047, 
        "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": "VMware, Inc.", 
        "ansible_uptime_seconds": 27961, 
        "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": "VMware", 
        "discovered_interpreter_python": "/usr/bin/python", 
        "gather_subset": [
            "all"
        ], 
        "module_setup": true
    }, 
    "changed": false
}