Ansible模块

常用模块

ping        # 测试主机的连通性
file        # 用于配置文件属性
yum         # 用于管理软件包
cron        # 配置计划任务
copy/fetch  # 复制文件到远程主机/复制远程主机文件到本地
command     # 在远程主机上执行命令
shell/raw   # 类似于command模块,支持管道与通配符(最常用)
user/group  # 配置用户/用户组
service     # 用于管理服务
ping        # 检测远程主机是否存活
setup       # 远程主机基本信息
mount       # 配置挂载点
script      # 脚本复制拷贝相关(最常用)
get_url     # 下载模块

user模块

append                 # (yes|no, default=no) yes:增量添加group,no: 全量变更group,之设置groups指定的group组
comment                # (default=no) 可选设置用户的账户的描述
createhome             # (yes|no,default=yes),创建用户时或家目录不存在时创建home目录
expires                # 用户过期时间,
force                  # (yes|no default=no) 强制,与state=absent结合使用时,效果等同于 userdel --force
generate_ssh_key       # (yes|no,default=no) 是否生成 ssh Key,不会覆盖已有的ssh Key
group                  # 可选。设置用户属组
groups                 # 设置用户附加群组,使用逗号分开多个群组home                   # 可选,设置用户家目录
login_class            # 可选,设置 bsd系统的用户登录class
move_home              # (yes|no,default=no,临时迁移用户家目录到指定目录)name                   #  用户名
non_unique             # Optionally when used with the -u option, this option allows to change the user ID to a non-unique
password               # 设置用户密码为指定的密码remove                 # 相当于 userdel remove
shell                  # 设置用户shell
skeleton # Optionally set a home skeleton directory. Requires createhome option! ssh_key_bits # 指定生成ssh key的加密位数 ssh_key_comment # 定义ssh key的注释 ssh_key_file # 指定ssh key文件名 ssh_key_passphrase # 设置ssh key密码 ssh_key_type # 指定ssh key 类型,默认rsa state # (default=present) present,新建用户;absent,删除用户 system # (yes|no,default=no) 当创建新账户时,该选项为yes,为用户设置系统账户,对已经存在的用户无效 uid # 可选,设置用户uid update_password # (no|always,default=always)  always:只有当密码不相同时才会更新密码,on_create:为新用户设置密码

示例:

//新增用户,使用bash shell,附加组为admins,dbagroup,家目录 /home/dba

ansible dba -m user -a "name=dba shell=/bin/bash groups=admins,dbagroup append=yes home=/home/dba state=present"

//修改用户属组
ansible dba -m  user -a "name=dba groups=dbagroup append=no"

//修改用户属性
ansible dba -m user -a "name=dba expires=1464775222(时间戳)"

// 删除用户
ansible dba -m user "name=dba state=abesent remove=yes"

//变更用户密码
ansible dba -m user -a "name=tom shell=/bin/bash password="密码 update_password=always"

这里的password为经过加密后的密码,两种方式生成加密密码:
方法①、
yum install expect makepasswd
mkpasswd --method=SHA-512

方法②、使用python passlib、getpass库生成密码
pip install passlib

生成密码(python3.x)
python -c "from passlib.hash import sha512_crypt;import getpass;print (sha512_crypt.encrypt(getpass.getpass()))"

普通加密算法
python -c "import crypt;print (crypt.crypt("redhat123","dba")"

应用层用户管理(如MySQL用户管理)

//添加一个mysql用户
ansible db -m mysql_user -a "login_host=localhost login_password="mysqlmima login_user=root name=stanly password=stanlymima priv=zabbix.*:all state=present"

synchronize 模块

模块参数说明

archive                # 是否采用归档模式同步,即以源文件相同属性同步到目标地址
checksum               # 是否效验
compress               # 开启压缩,默认为开启
copy_links             # 同步的时候是否复制连接
delete                 # 删除源中没有而目标存在的文件(即以推送方为主)
dest=                  # 目标地址路径
dest_port              # 目标接受的端口,ansible配置文件中的 ansible_ssh_port 变量优先级高于该 dest_port 变量
dirs                   # 以非递归的方式传输目录
existing_only          # Skip creating new files on receiver.
group                  # Preserve group
links                  # Copy symlinks as symlinks.
mode                   # 模式,rsync 同步的方式 PUSHPULL,默认都是推送push。如果你在使用拉取pull功能的时候,可以参考如下来实现mode=pull   更改推送模式为拉取模式
recursive              # 是否递归 yes/no
rsync_opts             # 使用rsync 的参数
rsync_path             # 服务的路径,指定 rsync 命令来在远程服务器上运行。这个参考rsync命令的--rsync-path参数,--rsync-path=PATH     # 指定远程服务器上的rsync命令所在路径信息
rsync_timeout          # 指定 rsync 操作的 IP 超时时间,和rsync命令的 --timeout 参数效果一样.
set_remote_user        # put user@ for the remote paths. If you have a custom ssh config to define the remote user for
src=‘#‘"                  # 源,同步的数据源
times                  # 
--exclude=.Git  忽略同步.git结尾的文件
由于模块默认启用了archive参数,该参数默认开启了recursive, links, perms, times, owner,group和-D参数。如果你将该参数设置为no,那么你将停止很多参数,比如会导致如下目的递归失败,导致无法拉取

使用synchronize模块,系统必须安装rsync 包,否则无法使用这个模块

示例:

ansible -i /etc/ansible/web_guanwang huizhongcf -m synchronize -a 'src=/var/lib/jenkins/workspace/HuiZhong/hzcfCMS/ dest=/usr/share/nginx/html/ rsync_opts="--exclude=.git" '

  

解释:
  指定 /etc/ansible/web_guanwang 目录下的hosts 文件 里huizhongcf 组名
  -m 指定模块名
  -a 命令
  rsync_opts 指定参数 忽略.git 结尾的文件 

shell模块

ansible web -m shell -a 'command' -o
ansible web -m shell -a 'uname -r ' -f 5 -o

 注解: -f 5 线程数  -o 输出

chdir命令

shell: chdir={{ tomcat_dir }}/../../ nohup rm -rf work & 

清除tomcat缓存操作

unarchive 模块


1、将ansible主机上的压缩包在本地解压缩后传到远程主机上,这种情况下,copy=yes. 本地解压缩,解压缩位置不是默认的目录,没找到或传完删了 后传到远程主机

2、将远程主机上的某个压缩包解压缩到指定路径下。这种情况下,需要设置copy=no 远程主机上面的操作,不涉及ansible服务端

用于解压文件,模块包含如下选项:
    copy:默认为yes。若为no,则要求目标主机上压缩包必须存在。
    creates:指定一个文件名,当该文件存在时,则解压指令不执行
    dest:远程主机上的一个路径,即文件解压的路径 
    grop:解压后的目录或文件的属组
    list_files:如果为yes,则会列出压缩包里的文件,默认为no,2.0版本新增的选项
    mode:解决后文件的权限
    src:如果copy为yes,则需要指定压缩文件的源路径 
    owner:解压后文件或目录的属主

示例:

src: "{{ war_files }}"
dest: "{{ tomcat_root }}"
copy: yes

copy模块

ansible web -m copy  -a 'src=host.py dest=/root/host.py' owner=root group=root  mode=644 backup=yes'

 参数说明

参数名       选项     必须      参数说明
backup       yes/no    no      备份远程节点上的原始文件,在拷贝之前。如果发生什么意外,原始文件还能使用。
content      yes/no    no      用来替代src,用于将指定文件的内容,拷贝到远程文件内
dest         yes/no   yes      用于定位远程节点上的文件,需要绝对路径。如果src指向的是文件夹,这个参数也必须是指向文件夹
directory_mode   yes/no   no      这个参数只能用于拷贝文件夹时候,这个设定后,文件夹内新建的文件会被拷贝。而老旧的不会被拷贝
follow       yes/no     no      当拷贝的文件夹内有link存在的时候,那么拷贝过去的也会有link
group        yes/no   no      指明文件属组
mode        yes/no    no      指明文件的权限
owner       yes/no      no      指明文件的属主
src        yes/no    no      文件源地址路径

yum模块

安装:ansible web  -m yum -a 'name=httpd state=latest' -f  5 -o
启动:ansible web  -m yum -a 'name=httpd state=started' -f 5  -o
验证:ansible web  -m shell -a 'netstat -ntlp| grep httpd ' -f  5 

 用户管理(user)模块

  首先openssl生成密码,然后user命令添加用户

生成密码
echo ansible|openssl passwd -1 -stdin

新建用户
ansible web -m user -a 'name=username password="生成的密码" ' -f 5 -o

authorized_key模块(批量安装sshkey)

ssh-keyscan xx.xx.xxx.xxx xxx.xxx.xxx.xxx >> /root/.ssh/known_hosts  ##测试貌似没通过

export ANSIBLE_HOST_KEY_CHECKING=False    ##可用

cat sshkey.yml --- - hosts: Partner gather_facts: false tasks: - name: install sshkey authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}" state=present
##执行 ansible-playbook -i /etc/ansible/Partner/hosts sshkey.yml --ask-pass

get_url模块

ansible web -m get_url -a "http://xx.com/xx.tar.gz dest=/tmp"

lineinfile模块

lineinfile模块针对文件特殊行,使用后端引用的正则表达式来替换,类似linux工具中的sed工具

//删除一行

- name: 删除一行
   lineinfile:
         dest:  /opt/playbook/test/hosts
         state: absent
         regexp: '^192.'
   tags: 
   - ...

//添加一行

- name: 添加一行(在最后添加)
   lineinfile:
         dest:  /opt/playbook/test/hosts
         line: '.....'
   tags: 
   - ...


//如果匹配到这一行,引用line这一行作为替换,如果匹配不到,则引用line这一样作为添加

 - name: Fully quoted a line
      lineinfile:
         dest: /opt/playbook/test/testfile
         state: present
         regexp: '^%wheel'
         line: '%wheel  ALL=(ALL)       NOPASSWD: ALL'

      tags:
        - testfile

//关于参数backrefs,backup使用。

  backrefs为no时,如果没有匹配,则添加一行line。如果匹配了,则把匹配内容替被换为line内容。

  backrefs为yes时,如果没有匹配,则文件保持不变。如果匹配了,把匹配内容替被换为line内容。

  backup为no时,没有匹配,则添加。如果匹配了,则替换

  backup为yes时,没有匹配,添加,如果匹配了,则替换

   
//示例
- name: test backrefs lineinfile: # backup: yes state: present dest: /opt/playbook/test/testfile regexp: '^#?bar' backrefs: yes line: 'bar' tags: - test_backrefs

设定regexp匹配不到,然后匹配“insertbefore”文本:

若匹配到“insertbefore”值=1:匹配“insertbefore”值之前的行,精确匹配行“line”;若匹配行“line”到,不做任何操作;若未匹配到,则在“insertbefore”值之前增加行“line”。

若匹配到“insertbefore”值>1:则只有最后一个“insertbefore”值为有效匹配值,其余同上。

- name: Lineinfile-iptables

  lineinfile:

      dest: /etc/sysconfig/iptables

      regexp: "ruler:other start"

      line: "{{item.line}}"

       insertbefore: "ruler:other end"

       backrefs: yes

       with_items:

        - { line: '-A INPUT -p tcp -m multiport --dports {{TOMCAT_PORT}} -j ACCEPT'}

优先匹配“regexp”,若匹配到则直接替换为“line”,未匹配到则分成下面的情况

①   存在backrefs: yes 参数:

A匹配“insertbefore”文本或者“insertafter”文本,若都未匹配到,则不会做任何操作。

B匹配到“insertbefore”文本(匹配多个最后一个有效),会从“insertbefore”文本往前匹配“line”,若匹配不到则新增行“line”,否则不做任何操作。

C匹配到“insertafter”文本(匹配多个最后一个有效),会从“insertafter”文本往后匹配“line”,若匹配不到则新增行“line”,否则不做任何操作。

②   不存在backrefs: yes 参数:

A匹配“insertbefore”文本或者“insertafter”文本,若都未匹配到,则在文件末尾新增行“line”。

B匹配到“insertbefore”文本(匹配多个最后一个有效),直接在“insertbefore”文本前面新增行“line”。

C匹配到“insertafter”文本(匹配多个最后一个有效),直接在“insertafter”文本后面新增行“line”。

- name: Lineinfile-iptables

  lineinfile:

    dest: /etc/sysconfig/iptables

    regexp: "ruler:other start"

    line: "{{item.line}}"

    insertbefore: "ruler:other end"

#   insertafter: "ruler:other start"

    backrefs: yes

  with_items:

    - { line: '-A INPUT -p tcp -m multiport --dports {{TOMCAT_PORT}} -j ACCEPT'}

示例

---
- hosts: test
  tasks:
  - name: 修改ssh配置
    lineinfile:
      dest: /etc/ssh/sshd_config        #要修改的配置文件
      regexp: "{{ item.regexp }}"        #要修改的行
      line: "{{ item.line }}"          #修改后的行
      state: present
    with_items:
    - { regexp: "^PasswordAuthentication" , line: "PasswordAuthentication no"}
    - { regexp: "^#PermitRootLogin", line: "PermitRootLogin no"}
    notify: restart ssh
 
  handlers:
  - name: restart ssh
    service: name=sshd.service state=restarted  

setup模块

setup模块主要用来显示主机的系统信息(cpu,ip,dns等等),以key:values的形式列出,最主要的功能就是这些信息可以被playbook的yml文件所引用

如:查看本机的主要ip:playbook里可以写成{{ ansible_ens32.ipv4.address }} (ansible_ens32为key,ipv4 为key的values值里的一个key,address为ipv4这个key的值里的key)获取到的值为ip:10.10.10.11

 如果想在命令行过滤: ansible 主机组 -m setup -a "filter=ansible_ens32"

10.10.10.11 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "172.17.0.1", 
            "10.10.10.11", 
            "172.18.0.1", 
            "192.168.122.1"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::250:56ff:fe93:e5c6"
        ], 
        "ansible_apparmor": {
            "status": "disabled"
        }, 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "06/22/2012", 
        "ansible_bios_version": "6.00", 
        "ansible_br_715339010b9c": {
            "active": false, 
            "device": "br-715339010b9c", 
            "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]"
            }, 
            "id": "8000.0242218ae431", 
            "interfaces": [], 
            "ipv4": {
                "address": "172.18.0.1", 
                "broadcast": "global", 
                "netmask": "255.255.0.0", 
                "network": "172.18.0.0"
            }, 
            "macaddress": "02:42:21:8a:e4:31", 
            "mtu": 1500, 
            "promisc": false, 
            "stp": false, 
            "type": "bridge"
        }, 
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-514.26.2.el7.x86_64", 
            "LANG": "en_US.UTF-8", 
            "crashkernel": "auto", 
            "quiet": true, 
            "rd.lvm.lv": "centos/swap", 
            "rhgb": true, 
            "ro": true, 
            "root": "/dev/mapper/centos-root"
        }, 
        "ansible_date_time": {
            "date": "2018-01-18", 
            "day": "18", 
            "epoch": "1516240309", 
            "hour": "09", 
            "iso8601": "2018-01-18T01:51:49Z", 
            "iso8601_basic": "20180118T095149945019", 
            "iso8601_basic_short": "20180118T095149", 
            "iso8601_micro": "2018-01-18T01:51:49.945264Z", 
            "minute": "51", 
            "month": "01", 
            "second": "49", 
            "time": "09:51:49", 
            "tz": "CST", 
            "tz_offset": "+0800", 
            "weekday": "Thursday", 
            "weekday_number": "4", 
            "weeknumber": "03", 
            "year": "2018"
        }, 
        "ansible_default_ipv4": {
            "address": "10.10.10.11", 
            "alias": "ens32", 
            "broadcast": "10.10.10.255", 
            "gateway": "10.10.10.1", 
            "interface": "ens32", 
            "macaddress": "00:50:56:93:e5:c6", 
            "mtu": 1500, 
            "netmask": "255.255.255.0", 
            "network": "10.10.10.0", 
            "type": "ether"
        }, 
        "ansible_default_ipv6": {}, 
        "ansible_devices": {
            "fd0": {
                "holders": [], 
                "host": "", 
                "model": null, 
                "partitions": {}, 
                "removable": "1", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "deadline", 
                "sectors": "8", 
                "sectorsize": "512", 
                "size": "4.00 KB", 
                "support_discard": "0", 
                "vendor": null
            }, 
            "sda": {
                "holders": [], 
                "host": "SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)", 
                "model": "Virtual disk", 
                "partitions": {
                    "sda1": {
                        "holders": [], 
                        "sectors": "1024000", 
                        "sectorsize": 512, 
                        "size": "500.00 MB", 
                        "start": "2048", 
                        "uuid": "d8dc2423-3de9-44d6-a983-ec66e55581bf"
                    }, 
                    "sda2": {
                        "holders": [
                            "centos-root", 
                            "centos-swap", 
                            "centos-home"
                        ], 
                        "sectors": "418404352", 
                        "sectorsize": 512, 
                        "size": "199.51 GB", 
                        "start": "1026048", 
                        "uuid": null
                    }
                }, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "deadline", 
                "sectors": "419430400", 
                "sectorsize": "512", 
                "size": "200.00 GB", 
                "support_discard": "0", 
                "vendor": "VMware"
            }, 
            "sr0": {
                "holders": [], 
                "host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)", 
                "model": "VMware IDE CDR10", 
                "partitions": {}, 
                "removable": "1", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "cfq", 
                "sectors": "2097151", 
                "sectorsize": "512", 
                "size": "1024.00 MB", 
                "support_discard": "0", 
                "vendor": "NECVMWar"
            }
        }, 
        "ansible_distribution": "CentOS", 
        "ansible_distribution_major_version": "7", 
        "ansible_distribution_release": "Core", 
        "ansible_distribution_version": "7.3.1611", 
        "ansible_dns": {
            "nameservers": [
                "219.141.136.10"
            ]
        }, 
        "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]"
            }, 
            "id": "8000.024263e72f42", 
            "interfaces": [], 
            "ipv4": {
                "address": "172.17.0.1", 
                "broadcast": "global", 
                "netmask": "255.255.0.0", 
                "network": "172.17.0.0"
            }, 
            "macaddress": "02:42:63:e7:2f:42", 
            "mtu": 1500, 
            "promisc": false, 
            "stp": false, 
            "type": "bridge"
        }, 
        "ansible_domain": "", 
        "ansible_effective_group_id": 0, 
        "ansible_effective_user_id": 0, 
        "ansible_ens32": {
            "active": true, 
            "device": "ens32", 
            "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_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": "off [fixed]", 
                "tx_tcp_ecn_segmentation": "off [fixed]", 
                "tx_tcp_segmentation": "on", 
                "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]"
            }, 
            "ipv4": {
                "address": "10.10.10.11", 
                "broadcast": "10.10.10.255", 
                "netmask": "255.255.255.0", 
                "network": "10.10.10.0"
            }, 
            "ipv6": [
                {
                    "address": "fe80::250:56ff:fe93:e5c6", 
                    "prefix": "64", 
                    "scope": "link"
                }
            ], 
            "macaddress": "00:50:56:93:e5:c6", 
            "module": "e1000", 
            "mtu": 1500, 
            "pciid": "0000:02:00.0", 
            "promisc": false, 
            "speed": 1000, 
            "type": "ether"
        }, 
        "ansible_env": {
            "CLASSPATH": ".:/usr/local/java/jdk1.8.0_151/jre/lib/rt.jar:/usr/local/java/jdk1.8.0_151/lib/dt.jar:/usr/local/java/jdk1.8.0_151/lib/tools.jar", 
            "HARDWARE_PLATFORM": "x86_64", 
            "HOME": "/root", 
            "JAVA_HOME": "/usr/local/java/jdk1.8.0_151", 
            "LANG": "en_US.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:/usr/local/java/jdk1.8.0_151/bin", 
            "PWD": "/root", 
            "SHELL": "/bin/bash", 
            "SHLVL": "2", 
            "SSH_CLIENT": "10.10.10.11 44884 22", 
            "SSH_CONNECTION": "10.10.10.11 44884 10.10.10.11 22", 
            "SSH_TTY": "/dev/pts/2", 
            "TERM": "xterm", 
            "USER": "root", 
            "XDG_RUNTIME_DIR": "/run/user/0", 
            "XDG_SESSION_ID": "4036", 
            "_": "/usr/bin/python"
        }, 
        "ansible_fips": false, 
        "ansible_form_factor": "Other", 
        "ansible_fqdn": "bogon", 
        "ansible_gather_subset": [
            "hardware", 
            "network", 
            "virtual"
        ], 
        "ansible_hostname": "bogon", 
        "ansible_interfaces": [
            "docker0", 
            "lo", 
            "ens32", 
            "br-715339010b9c", 
            "virbr0-nic", 
            "virbr0"
        ], 
        "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]"
            }, 
            "ipv4": {
                "address": "127.0.0.1", 
                "broadcast": "host", 
                "netmask": "255.0.0.0", 
                "network": "127.0.0.0"
            }, 
            "ipv6": [
                {
                    "address": "::1", 
                    "prefix": "128", 
                    "scope": "host"
                }
            ], 
            "mtu": 65536, 
            "promisc": false, 
            "type": "loopback"
        }, 
        "ansible_lvm": {
            "lvs": {
                "home": {
                    "size_g": "148.70", 
                    "vg": "centos"
                }, 
                "root": {
                    "size_g": "50.00", 
                    "vg": "centos"
                }, 
                "swap": {
                    "size_g": "0.75", 
                    "vg": "centos"
                }
            }, 
            "vgs": {
                "centos": {
                    "free_g": "0.06", 
                    "num_lvs": "3", 
                    "num_pvs": "1", 
                    "size_g": "199.51"
                }
            }
        }, 
        "ansible_machine": "x86_64", 
        "ansible_machine_id": "2b31f6e89b764c1dbf1feed150e6387e", 
        "ansible_memfree_mb": 1379, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 10284, 
                "used": 5603
            }, 
            "real": {
                "free": 1379, 
                "total": 15887, 
                "used": 14508
            }, 
            "swap": {
                "cached": 0, 
                "free": 767, 
                "total": 767, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 15887, 
        "ansible_mounts": [
            {
                "device": "/dev/mapper/centos-root", 
                "fstype": "xfs", 
                "mount": "/", 
                "options": "rw,relatime,attr2,inode64,noquota", 
                "size_available": 28555288576, 
                "size_total": 53660876800, 
                "uuid": "8767ae54-8e15-434f-a128-cfcf10e9dd94"
            }, 
            {
                "device": "/dev/sda1", 
                "fstype": "xfs", 
                "mount": "/boot", 
                "options": "rw,relatime,attr2,inode64,noquota", 
                "size_available": 295768064, 
                "size_total": 520794112, 
                "uuid": "d8dc2423-3de9-44d6-a983-ec66e55581bf"
            }, 
            {
                "device": "/dev/mapper/centos-home", 
                "fstype": "xfs", 
                "mount": "/home", 
                "options": "rw,relatime,attr2,inode64,noquota", 
                "size_available": 118263951360, 
                "size_total": 159582416896, 
                "uuid": "6cb4a5e8-c6ef-4aa0-9962-c0f9dc5a3bd7"
            }, 
            {
                "device": "/dev/mapper/centos-root", 
                "fstype": "xfs", 
                "mount": "/var/lib/docker/overlay", 
                "options": "rw,relatime,attr2,inode64,noquota,bind", 
                "size_available": 28555288576, 
                "size_total": 53660876800, 
                "uuid": "8767ae54-8e15-434f-a128-cfcf10e9dd94"
            }
        ], 
        "ansible_nodename": "bogon", 
        "ansible_os_family": "RedHat", 
        "ansible_pkg_mgr": "yum", 
        "ansible_processor": [
            "GenuineIntel", 
            "Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz"
        ], 
        "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-42 13 5f e0 8d cd 65 83-11 c5 1a 9d 2a db af c6", 
        "ansible_product_uuid": "42135FE0-8DCD-6583-11C5-1A9D2ADBAFC6", 
        "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_service_mgr": "systemd", 
        "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE700gduIJpJxhp8EqsoUZRzoilVN05yzb9iK5nn9M6dJ0Yw6tkySsr6su4hc2Zpb2fzWpFofvG/hzYtefL4HOs=", 
        "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAINyD5dVhLehvWunswzhduxK0JQI8Fq1qItw/0k86MC76", 
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDUK3RE3vy6eICHEqVwZ5zgksP1+J0oboKnCrkwYJxCFEPzGG6eQoyfRANIp0fjUagGj5AXebBdCagzrneVH7zNjxs2+2gIrH0iDbhiSMqKXCltnJwJssxI4XgXXJlFa42Wh2bCC6qUf3+o+nCkwQWBhGsZUM//GkRsIDNdXrnX7tfIKham8i205GQlADAxO2OaXsnsJ7/2IxBCabFyaJ55Si1gwqBhF+XtCCeTXCxX9AiUvu8lTSB69fukPDugh45pnq05tFU6IoY9F2EgTIK9eNP8TxAa1cwzRbUTtCYHdC2qEijX1hv43n+PwHxf2Q4pZ0HmUBfgRwOFx14LKh7l", 
        "ansible_swapfree_mb": 767, 
        "ansible_swaptotal_mb": 767, 
        "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": 1275247, 
        "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_virbr0": {
            "active": false, 
            "device": "virbr0", 
            "features": {
                "busy_poll": "off [fixed]", 
                "fcoe_mtu": "off [fixed]", 
                "generic_receive_offload": "on", 
                "generic_segmentation_offload": "on", 
                "highdma": "off [requested 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": "off", 
                "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 [requested on]", 
                "tx_gre_segmentation": "on", 
                "tx_gso_robust": "off [requested 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": "off [requested on]", 
                "tx_sit_segmentation": "on", 
                "tx_tcp6_segmentation": "off [requested on]", 
                "tx_tcp_ecn_segmentation": "off [requested on]", 
                "tx_tcp_segmentation": "off [requested on]", 
                "tx_udp_tnl_segmentation": "on", 
                "tx_vlan_offload": "on", 
                "tx_vlan_stag_hw_insert": "off [fixed]", 
                "udp_fragmentation_offload": "off [requested on]", 
                "vlan_challenged": "off [fixed]"
            }, 
            "id": "8000.525400b76fef", 
            "interfaces": [
                "virbr0-nic"
            ], 
            "ipv4": {
                "address": "192.168.122.1", 
                "broadcast": "192.168.122.255", 
                "netmask": "255.255.255.0", 
                "network": "192.168.122.0"
            }, 
            "macaddress": "52:54:00:b7:6f:ef", 
            "mtu": 1500, 
            "promisc": false, 
            "stp": true, 
            "type": "bridge"
        }, 
        "ansible_virbr0_nic": {
            "active": false, 
            "device": "virbr0-nic", 
            "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 [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": "off", 
                "tx_checksum_fcoe_crc": "off [fixed]", 
                "tx_checksum_ip_generic": "off [requested on]", 
                "tx_checksum_ipv4": "off [fixed]", 
                "tx_checksum_ipv6": "off [fixed]", 
                "tx_checksum_sctp": "off [fixed]", 
                "tx_checksumming": "off", 
                "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", 
                "tx_scatter_gather": "on", 
                "tx_scatter_gather_fraglist": "on", 
                "tx_sctp_segmentation": "off [fixed]", 
                "tx_sit_segmentation": "off [fixed]", 
                "tx_tcp6_segmentation": "off [requested on]", 
                "tx_tcp_ecn_segmentation": "off [requested on]", 
                "tx_tcp_segmentation": "off [requested on]", 
                "tx_udp_tnl_segmentation": "off [fixed]", 
                "tx_vlan_offload": "on", 
                "tx_vlan_stag_hw_insert": "on", 
                "udp_fragmentation_offload": "off [requested on]", 
                "vlan_challenged": "off [fixed]"
            }, 
            "macaddress": "52:54:00:b7:6f:ef", 
            "mtu": 1500, 
            "promisc": true, 
            "type": "ether"
        }, 
        "ansible_virtualization_role": "guest", 
        "ansible_virtualization_type": "VMware", 
        "module_setup": true
    }, 
    "changed": false
}
原文地址:https://www.cnblogs.com/FRESHMANS/p/8119224.html