facts 指的是 ansible_facts 变量,ansible 中使用 setup 模块来获取,包含系统的大部分基础硬件信息,

[root@10_1_162_39 host_vars]# ll
total
-rw-r--r-- root root May : hosts
-rw-r--r-- root root May : test1.yaml
-rw-r--r-- root root May : test.playbook

获取所有变量的命令如下,其中的变量可以在 playbook 入口 yaml 文件中使用,本文在 test.playbook 中引用

[root@10_1_162_39 host_vars]# ansible 10.1.162.18 -m setup -i hosts
10.1.162.18 | SUCCESS => {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.238.129"
],
"ansible_all_ipv6_addresses": [
"fe80::20c:29ff:fe21:bd17"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "07/02/2015",
"ansible_bios_version": "6.00",
"ansible_cmdline": {
"BOOT_IMAGE": "vmlinuz0",
"initrd": "initrd0.img",
"liveimg": true,
"nodiskmount": true,
"nolvmmount": true,
"quiet": true,
"rd.dm": "",
"rd.luks": "",
"rd.md": "",
"rhgb": true,
"ro": true,
"root": "live:CDLABEL=CentOS-6.8-x86_64-LiveCD",
"rootfstype": "auto"
},
"ansible_date_time": {
"date": "2017-05-05",
"day": "",
"epoch": "",
"hour": "",
"iso8601": "2017-05-05T21:02:35Z",
"iso8601_basic": "20170505T170235836807",
"iso8601_basic_short": "20170505T170235",
"iso8601_micro": "2017-05-05T21:02:35.836916Z",
"minute": "",
"month": "",
"second": "",
"time": "17:02:35",
"tz": "EDT",
"tz_offset": "-0400",
"weekday": "Friday",
"weekday_number": "",
"weeknumber": "",
"year": ""
},
"ansible_default_ipv4": {
"address": "192.168.238.129",
"alias": "eth0",
"broadcast": "192.168.238.255",
"gateway": "192.168.238.2",
"interface": "eth0",
"macaddress": "00:0c:29:21:bd:17",
"mtu": ,
"netmask": "255.255.255.0",
"network": "192.168.238.0",
"type": "ether"
},
"ansible_default_ipv6": {},
"ansible_devices": {
"sda": {
"holders": [],
"host": "SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)",
"model": "VMware Virtual S",
"partitions": {
"sda1": {
"holders": [],
"sectors": "",
"sectorsize": ,
"size": "19.99 GB",
"start": "",
"uuid": "e211add0-38ea-4214-9c56-b193e6749d4f"
}
},
"removable": "",
"rotational": "",
"sas_address": null,
"sas_device_handle": null,
"scheduler_mode": "cfq",
"sectors": "",
"sectorsize": "",
"size": "20.00 GB",
"support_discard": "",
"vendor": "VMware,"
},
"sr0": {
"holders": [],
"host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)",
"model": "VMware IDE CDR10",
"partitions": {},
"removable": "",
"rotational": "",
"sas_address": null,
"sas_device_handle": null,
"scheduler_mode": "cfq",
"sectors": "",
"sectorsize": "",
"size": "2.74 GB",
"support_discard": "",
"vendor": "NECVMWar"
}
},
"ansible_distribution": "CentOS",
"ansible_distribution_major_version": "",
"ansible_distribution_release": "Final",
"ansible_distribution_version": "6.8",
"ansible_dns": {
"domain": "localdomain",
"nameservers": [
"192.168.238.2"
],
"search": [
"localdomain",
"centos"
]
},
"ansible_domain": "centos",
"ansible_env": {
"G_BROKEN_FILENAMES": "",
"HOME": "/root",
"LANG": "en_US.UTF-8",
"LESSOPEN": "||/usr/bin/lesspipe.sh %s",
"LOGNAME": "root",
"MAIL": "/var/mail/root",
"PATH": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin",
"PWD": "/root",
"SELINUX_LEVEL_REQUESTED": "",
"SELINUX_ROLE_REQUESTED": "",
"SELINUX_USE_CURRENT_RANGE": "",
"SHELL": "/bin/bash",
"SHLVL": "",
"SSH_ASKPASS": "/usr/libexec/openssh/gnome-ssh-askpass",
"SSH_CLIENT": "10.1.162.39 39522 22",
"SSH_CONNECTION": "10.1.162.39 39522 192.168.238.129 22",
"SSH_TTY": "/dev/pts/5",
"TERM": "linux",
"USER": "root",
"_": "/usr/bin/python"
},
"ansible_eth0": {
"active": true,
"device": "eth0",
"features": {
"fcoe_mtu": "off [fixed]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "off [requested on]",
"highdma": "off [fixed]",
"large_receive_offload": "off [fixed]",
"loopback": "off [fixed]",
"netns_local": "off [fixed]",
"ntuple_filters": "off [fixed]",
"receive_hashing": "off [fixed]",
"rx_checksumming": "off [fixed]",
"rx_vlan_filter": "off [fixed]",
"rx_vlan_offload": "off [fixed]",
"scatter_gather": "off",
"tcp_segmentation_offload": "off",
"tx_checksum_fcoe_crc": "off [fixed]",
"tx_checksum_ip_generic": "off [fixed]",
"tx_checksum_ipv4": "off [fixed]",
"tx_checksum_ipv6": "off [fixed]",
"tx_checksum_sctp": "off [fixed]",
"tx_checksum_unneeded": "off [fixed]",
"tx_checksumming": "off",
"tx_fcoe_segmentation": "off [fixed]",
"tx_gre_segmentation": "off [fixed]",
"tx_gso_robust": "off [fixed]",
"tx_lockless": "off [fixed]",
"tx_scatter_gather": "off [fixed]",
"tx_scatter_gather_fraglist": "off [fixed]",
"tx_tcp6_segmentation": "off [fixed]",
"tx_tcp_ecn_segmentation": "off [fixed]",
"tx_tcp_segmentation": "off [fixed]",
"tx_udp_tnl_segmentation": "off [fixed]",
"tx_vlan_offload": "off [fixed]",
"udp_fragmentation_offload": "off [fixed]",
"vlan_challenged": "off [fixed]"
},
"ipv4": {
"address": "192.168.238.129",
"broadcast": "192.168.238.255",
"netmask": "255.255.255.0",
"network": "192.168.238.0"
},
"ipv6": [
{
"address": "fe80::20c:29ff:fe21:bd17",
"prefix": "",
"scope": "link"
}
],
"macaddress": "00:0c:29:21:bd:17",
"module": "pcnet32",
"mtu": ,
"pciid": "0000:02:01.0",
"promisc": false,
"type": "ether"
},
"ansible_fips": false,
"ansible_form_factor": "Other",
"ansible_fqdn": "livecd.centos",
"ansible_gather_subset": [
"hardware",
"network",
"virtual"
],
"ansible_hostname": "livecd",
"ansible_interfaces": [
"lo",
"eth0"
],
"ansible_kernel": "2.6.32-642.el6.x86_64",
"ansible_lo": {
"active": true,
"device": "lo",
"features": {
"fcoe_mtu": "off [fixed]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "on",
"highdma": "on [fixed]",
"large_receive_offload": "off [fixed]",
"loopback": "on [fixed]",
"netns_local": "on [fixed]",
"ntuple_filters": "off [fixed]",
"receive_hashing": "off [fixed]",
"rx_checksumming": "on [fixed]",
"rx_vlan_filter": "off [fixed]",
"rx_vlan_offload": "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": "off [fixed]",
"tx_checksum_unneeded": "off [fixed]",
"tx_checksumming": "on",
"tx_fcoe_segmentation": "off [fixed]",
"tx_gre_segmentation": "off [fixed]",
"tx_gso_robust": "off [fixed]",
"tx_lockless": "on [fixed]",
"tx_scatter_gather": "on [fixed]",
"tx_scatter_gather_fraglist": "on [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]",
"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": "",
"scope": "host"
}
],
"mtu": ,
"promisc": false,
"type": "loopback"
},
"ansible_lvm": {
"lvs": {},
"vgs": {}
},
"ansible_machine": "x86_64",
"ansible_machine_id": "fbd601d6c3cc5bbb8e9b21b300000010",
"ansible_memfree_mb": ,
"ansible_memory_mb": {
"nocache": {
"free": ,
"used":
},
"real": {
"free": ,
"total": ,
"used":
},
"swap": {
"cached": ,
"free": ,
"total": ,
"used":
}
},
"ansible_memtotal_mb": ,
"ansible_mounts": [
{
"device": "/dev/mapper/live-rw",
"fstype": "ext4",
"mount": "/",
"options": "rw,noatime",
"size_available": ,
"size_total": ,
"uuid": "N/A"
},
{
"device": "/dev/sr0",
"fstype": "iso9660",
"mount": "/mnt/live",
"options": "ro",
"size_available": ,
"size_total": ,
"uuid": "N/A"
},
{
"device": "/tmp",
"fstype": "tmpfs",
"mount": "/tmp",
"options": "rw,rootcontext=\"system_u:object_r:tmp_t:s0\"",
"size_available": ,
"size_total": ,
"uuid": "N/A"
}
],
"ansible_nodename": "livecd.centos",
"ansible_os_family": "RedHat",
"ansible_pkg_mgr": "yum",
"ansible_processor": [
"GenuineIntel",
"Intel(R) Xeon(R) CPU E5-2650 v3 @ 2.30GHz"
],
"ansible_processor_cores": ,
"ansible_processor_count": ,
"ansible_processor_threads_per_core": ,
"ansible_processor_vcpus": ,
"ansible_product_name": "VMware Virtual Platform",
"ansible_product_serial": "VMware-56 4d e4 27 2b 45 f8 74-e5 17 57 47 ab 21 bd 17",
"ansible_product_uuid": "564DE427-2B45-F874-E517-5747AB21BD17",
"ansible_product_version": "None",
"ansible_python": {
"executable": "/usr/bin/python",
"has_sslcontext": false,
"type": "CPython",
"version": {
"major": ,
"micro": ,
"minor": ,
"releaselevel": "final",
"serial":
},
"version_info": [
,
,
,
"final", ]
},
"ansible_python_version": "2.6.6",
"ansible_selinux": {
"config_mode": "enforcing",
"mode": "enforcing",
"policyvers": ,
"status": "enabled",
"type": "targeted"
},
"ansible_service_mgr": "upstart",
"ansible_ssh_host_key_dsa_public": "AAAAB3NzaC1kc3MAAACBAN7JNklx9irSPQZeO+xeiUhXNoETLapnTGkcm3ZR/WDqm1HxX+8EPELNzPK0/kUEIouJTQN07vq/Rqhrm0wGO04JzohixiaAIlgxlWqM7aRtgJ29seZZw0SZ2EVnqfalLqO8kPYjqCXL8QBZVJOdvqLwzz/pOxuHGFHh5uKj5SN5AAAAFQCGSiIuqxBcCVS8CYUWjez4HmuatwAAAIBLJj4V3WOo6+9JVmy2RpBJkLimjEGSfsmUEMyRcggTWyBwMnKC4AweZOoGzgBoBtXm4rCgQdzze+jlbL1tQquQQXUoFnaV6eIxRBBOuHa48F3PH4RapLVosBf0U3BfqBZ5l1GhquqPtLug1XfJrUm27JJcuSIc5yVbMkHIoi5KeQAAAIBFR5wRIEyznDQfSMNtctTYExagg/7FOLKtNVOl0J1xbwNOwpF8fUI0OtgWQeHzqDbwTE/Gtp92v6CvEFVTMgcQ+FeUYDcFNPzia+Vdk5C1Un6q8Ejx2hIc+f1Y9fg0yuj6/J0G3kOoIPLOTXFWd1HHSdEr+7dgs8F2F0gsMB/W8/x2Q==",
"ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAABIwAAAQAQEFAqY4Aut3/NGPYJaqMVeVociBafC0Qbc29IKKSy6i0UodrGE3UXAWf/gmNSktkjqZ8UHBiXJAzCAMwyonlm/l4M+ZwYoJ8VjtUZtz/9cGXHS+P2qPID8mMyxvFMn9xd0w623GkSJfqMg0wW9Lwywd4hceq5qp5n8L1tDDCpNxbbAifKXoZmWFejhXU9qzJ8L4Vw/a+XzCbfiTmDifzL7MX2Yt/dy0SWeKbWnjjfDCDtFDtMYh/Uvin/J5FI7JEcSxP/1gjZZO7ivqhQpWNqkqkLgZJ/X2YVODsNh0GaTYfEbOrCKKHbstc0ypppE0bNe91HTSZfvkzkKwV6jzt2T3u8Q==",
"ansible_swapfree_mb": ,
"ansible_swaptotal_mb": ,
"ansible_system": "Linux",
"ansible_system_capabilities": [],
"ansible_system_capabilities_enforced": "False",
"ansible_system_vendor": "VMware, Inc.",
"ansible_uptime_seconds": ,
"ansible_user_dir": "/root",
"ansible_user_gecos": "root",
"ansible_user_gid": ,
"ansible_user_id": "root",
"ansible_user_shell": "/bin/bash",
"ansible_user_uid": ,
"ansible_userspace_architecture": "x86_64",
"ansible_userspace_bits": "",
"ansible_virtualization_role": "guest",
"ansible_virtualization_type": "VMware",
"module_setup": true
},
"changed": false
}
[root@10_1_162_39 host_vars]#

引用变量

[root@10_1_162_39 host_vars]# cat test.playbook
---
- hosts: "{{ host }}"
gather_facts: true
remote_user: root
tasks:
- shell: ifconfig
register: output
- debug: var=output.stdout
- debug: msg=" ansible_system={{ ansible_system }}"
- debug: msg={{ ansible_selinux }}

运行 playbook 命令

[root@10_1_162_39 host_vars]# ansible-playbook test.playbook -i hosts -e host=10.1.162.18

PLAY [10.1.162.18] *************************************************************

TASK [setup] *******************************************************************
ok: [10.1.162.18] TASK [command] *****************************************************************
changed: [10.1.162.18] TASK [debug] *******************************************************************
ok: [10.1.162.18] => {
"output.stdout": "eth0 Link encap:Ethernet HWaddr 00:0C:29:21:BD:17 \n inet addr:192.168.238.129 Bcast:192.168.238.255 Mask:255.255.255.0\n inet6 addr: fe80::20c:29ff:fe21:bd17/64 Scope:Link\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\n RX packets:309551 errors:0 dropped:0 overruns:0 frame:0\n TX packets:125322 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1000 \n RX bytes:368636410 (351.5 MiB) TX bytes:7103077 (6.7 MiB)\n Interrupt:19 Base address:0x2000 \n\nlo Link encap:Local Loopback \n inet addr:127.0.0.1 Mask:255.0.0.0\n inet6 addr: ::1/128 Scope:Host\n UP LOOPBACK RUNNING MTU:65536 Metric:1\n RX packets:8 errors:0 dropped:0 overruns:0 frame:0\n TX packets:8 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:0 \n RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)"
} TASK [debug] *******************************************************************
ok: [10.1.162.18] => {
"msg": " ansible_system=Linux"
} TASK [debug] *******************************************************************
ok: [10.1.162.18] => {
"msg": {
"config_mode": "enforcing",
"mode": "enforcing",
"policyvers": ,
"status": "enabled",
"type": "targeted"
}
} PLAY RECAP *********************************************************************
10.1.162.18 : ok= changed= unreachable= failed= [root@10_1_162_39 host_vars]#

ansible facts 获取硬件信息的更多相关文章

  1. WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法

    原文:WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法 今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都是可以提取出来的,就自己把那些公共部分提出出来,以后如果要获取 某部分的 ...

  2. linux下dmidecode命令获取硬件信息

    linux下dmidecode命令获取硬件信息 2 A+ 所属分类:Linux 运维工具 dmidecode在 Linux 系统下获取有关硬件方面的信息.dmidecode 遵循 SMBIOS/DMI ...

  3. C#获取硬件信息

    //硬件信息 public class GF_Hardware { /// <summary> /// cpu序列号 /// </summary> /// <return ...

  4. 获取硬件信息的delphi源码CPUID、操作系统、Mac物理地址、计算机名称、IP地址、用户名

    {-----------------------------------------------------------------------------作者:sushengmiyan 2013.0 ...

  5. Web网站中利用JavaScript中ActiveXObject对象获取硬件信息(显示器数量、分辨率)从而进行单双屏跳转

    前言:最近这两天工作上,要实现一个功能,在好友阿聪的帮助下,算是比较好的解决了这个需求. B/S的Web网站,需要实现点击按钮时,根据客户端连接的显示屏(监视器)数量进行,单双屏跳转显示新页面. 由于 ...

  6. Powershell获取硬件信息

    1.获取系统的BIOS的信息: Get-WMIObject -Class Win32_BIOS 2.获取内存信息: Get-WMIObject -Class Win32_PhysicalMemory ...

  7. C#通过WMI获取硬件信息

    有时候需要得到硬件信息绑定用户登录 代码如下: private string GetProcessSerialNumber() { try { ManagementObjectCollection P ...

  8. 使用dmidecode在Linux下获取硬件信息

    dmidecode命令可以让你在Linux系统下获取有关硬件方面的信息.dmidecode的作用是将DMI数据库中的信息解码,以可读的文本方式显示.由于DMI信息可以人为修改,因此里面的信息不一定是系 ...

  9. Windows PHone 8 获取硬件信息

    /// <summary> /// 获取系统信息 /// </summary> private string GetDeviceInfo() { StringBuilder s ...

随机推荐

  1. 原生js实现三级复选框

    工作中要做一个三级的复选框,用js实现了一下,从项目中把相关代码抽取出来了,有相关需求的可以参考一下.亲测可用. <!DOCTYPE html> <html> <head ...

  2. python帮助信息查看以及笔记

    如何获取使用帮助: 获取对象支持使用的属性和方法:dir() dir()不带参数时,返回当前范围内的变量.方法和定义的类型列表:带参数时,返回参数的属性.方法列表.如果参数包含方法__dir__(), ...

  3. Linux逻辑卷的拉伸和缩小

    相对于普通磁盘优势是逻辑卷可以在线动态的拉伸(不用先unmount操作),只要vg中有足够的空间即可 1:首先查看vg是否有足够的空间 [root@gechong mapper]# vgdisplay ...

  4. FileOperator 文件(夹)操作类

    public class FileOperator { /** * 复制文件目录 * @param srcDir 要复制的源目录 eg:/mnt/sdcard/DB * @param destDir ...

  5. neo4j 常用命令查询,以及更新 节点 的 label 名 和 property 名

    常用命令查询 https://neo4j.com/docs/cypher-refcard/current/ 更新节点的 labels 有时候 发现节点的 label 名字起错了怎么修改呢?!一个节点是 ...

  6. MongoDB 数据库命令

    数据库命令 连接成功后,默认使用test数据库 查看当前数据库名称 db 查看所有数据库名称,列出所有在物理上存在的数据库 show dbs 切换数据库,如果数据库不存在也并不创建,直到插入数据或创建 ...

  7. 序列比对之Biostrings包

    基本概念 Biostrings包很重要的3个功能是进行Pairwise sequence alignment 和Multiple sequence alignment及 Pattern finding ...

  8. 大型运输行业实战_day07_2_数据字典实现

    1.数据字典表 CREATE TABLE `dic` ( `id` ) NOT NULL AUTO_INCREMENT, `table_name` ) DEFAULT NULL, `field_nam ...

  9. 元素的定位tag_name,link_text,class_name

    tag_name 就是根据HTML的标签的名称来定位的: 案例:打开我要自学网,会有用户名和密码的输入框 例如:拿51zxw.net为例 from time import sleep #加载浏览器驱动 ...

  10. 【校招面试 之 剑指offer】第18题 删除链表中的节点

    题目一:在O(1)时间内删除链表节点. 给定单项链表的头指针和一个节点指针,定义一个函数在O(1)时间内删除该节点. 思路:(1)如果要删除的节点不是链表的尾节点,则将被删除节点的内容复制到该节点,然 ...