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

[root@10_1_162_39 host_vars]# ll
total 16
-rw-r--r-- 1 root root   44 May  5 14:55 hosts
-rw-r--r-- 1 root root  134 May  5 09:40 test1.yaml
-rw-r--r-- 1 root root  200 May  5 16:56 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": "0", "rd.luks": "0", "rd.md": "0", "rhgb": true, "ro": true, "root": "live:CDLABEL=CentOS-6.8-x86_64-LiveCD", "rootfstype": "auto"}, "ansible_date_time": {"date": "2017-05-05", "day": "05", "epoch": "1494018155", "hour": "17", "iso8601": "2017-05-05T21:02:35Z", "iso8601_basic": "20170505T170235836807", "iso8601_basic_short": "20170505T170235", "iso8601_micro": "2017-05-05T21:02:35.836916Z", "minute": "02", "month": "05", "second": "35", "time": "17:02:35", "tz": "EDT", "tz_offset": "-0400", "weekday": "Friday", "weekday_number": "5", "weeknumber": "18", "year": "2017"}, "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": 1500, "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": "41929587", "sectorsize": 512, "size": "19.99 GB", "start": "63", "uuid": "e211add0-38ea-4214-9c56-b193e6749d4f"}}, "removable": "0", "rotational": "1", "sas_address": null, "sas_device_handle": null, "scheduler_mode": "cfq", "sectors": "41943040", "sectorsize": "512", "size": "20.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": "1437696", "sectorsize": "2048", "size": "2.74 GB", "support_discard": "0", "vendor": "NECVMWar"}}, "ansible_distribution": "CentOS", "ansible_distribution_major_version": "6", "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": "1", "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": "2", "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": "64", "scope": "link"}], "macaddress": "00:0c:29:21:bd:17", "module": "pcnet32", "mtu": 1500, "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": "128", "scope": "host"}], "mtu": 65536, "promisc": false, "type": "loopback"}, "ansible_lvm": {"lvs": {}, "vgs": {}}, "ansible_machine": "x86_64", "ansible_machine_id": "fbd601d6c3cc5bbb8e9b21b300000010", "ansible_memfree_mb": 72, "ansible_memory_mb": {"nocache": {"free": 682, "used": 314}, "real": {"free": 72, "total": 996, "used": 924}, "swap": {"cached": 0, "free": 0, "total": 0, "used": 0}}, "ansible_memtotal_mb": 996, "ansible_mounts": [{"device": "/dev/mapper/live-rw", "fstype": "ext4", "mount": "/", "options": "rw,noatime", "size_available": 2155237376, "size_total": 4093313024, "uuid": "N/A"}, {"device": "/dev/sr0", "fstype": "iso9660", "mount": "/mnt/live", "options": "ro", "size_available": 0, "size_total": 735934464, "uuid": "N/A"}, {"device": "/tmp", "fstype": "tmpfs", "mount": "/tmp", "options": "rw,rootcontext=\"system_u:object_r:tmp_t:s0\"", "size_available": 521654272, "size_total": 522248192, "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": 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 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": 2, "micro": 6, "minor": 6, "releaselevel": "final", "serial": 0}, "version_info": [2, 6, 6, "final", 0]}, "ansible_python_version": "2.6.6", "ansible_selinux": {"config_mode": "enforcing", "mode": "enforcing", "policyvers": 24, "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": 0, "ansible_swaptotal_mb": 0, "ansible_system": "Linux", "ansible_system_capabilities": [], "ansible_system_capabilities_enforced": "False", "ansible_system_vendor": "VMware, Inc.", "ansible_uptime_seconds": 92488, "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", "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: trueremote_user: roottasks:- shell: ifconfigregister: 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.18PLAY [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": 24, "status": "enabled", "type": "targeted"}
}PLAY RECAP *********************************************************************
10.1.162.18                : ok=5    changed=1    unreachable=0    failed=0   [root@10_1_162_39 host_vars]# 

转载于:https://www.cnblogs.com/lxmhhy/p/6813953.html

ansible facts 获取硬件信息相关推荐

  1. 如何获取服务器机器码_dmidecode命令详解(获取硬件信息)

    如何获取服务器机器码_dmidecode命令详解_获取硬件信息 零.获取linux服务器机器码 一.dmidecode简介 二.dmidecode的作用 三.dmidecode命令用法 dmideco ...

  2. C#获取硬件信息的方法

    在很多情况下,你可能都需要得到微机的硬件信息.比如:你想给你的软件加锁,不让别人随便访问. 最有效的办法是获取CPU的序列号,然后让你的软件只能运行在有这样的CPU序列号的机器上.众所周知,CPU序列 ...

  3. 联想台式计算机的设备序列号,WMI获取硬件信息封装函数方法(联想台式机出厂编号 CPUID BIOS序列号 硬盘信息 显卡信息 MAC地址)...

    今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都是可以提取出来的,就自己把那些公共部分提出出来,以后如果要获取某部分的硬件信息就不用写一个一个的函数,比如获取MAC地址就写一个获取MAC地 ...

  4. Delphi D10.X安卓APP开发中获取硬件信息及手机号

    Demo与代码已上传到CSDN下载. 这里简单说一下代码内容,完整代码请自行下载,不清楚的欢迎留言交流. 前言 演示Demo使用了我自己开发的一个控件,TLayoutPro <Delphi D1 ...

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

    转载请保留本文链接地址:http://blog.csdn.net/sushengmiyan/article/details/8545673 {----------------------------- ...

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

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

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

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

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

    dmidecode在 Linux 系统下获取有关硬件方面的信息.dmidecode 遵循 SMBIOS/DMI 标准,以一种可读的方式dump出机器的DMI(Desktop Management In ...

  9. dmidecode 命令详解(获取硬件信息)

    一.简介 DMI (Desktop Management Interface, DMI)就是帮助收集电脑系统信息的管理系统,DMI信息的收集必须在严格遵照SMBIOS规范的前提下进行. SMBIOS( ...

最新文章

  1. 两轴机械臂+机械爪整体控制板设计与机械爪控制调试
  2. 不要随意重装你的操作系统
  3. 3个可以写进简历的京东AI NLP项目实战,走完这五步就是Top算法工程师
  4. mysql error manager,MYSQL Starting MySQL. ERROR! Manager of pid-file quit without updating file
  5. 62. Leetcode 34. 在排序数组中查找元素的第一个和最后一个位置 (二分查找-局部有序)
  6. python中常见的双下方法_python中常见的双下方法_python面向对象(5)__特殊双下方法...
  7. python多线程信息提示
  8. 【图像分割】图像分割专栏栏主自述:分割,我们究竟在研究什么?
  9. Jmeter提取响应结果中的json数据
  10. 【C#】三种结构:顺序、分支(if、switch、条件运算符)、循环
  11. Linux文本界面配置yum源,修改Linux默认语言 配置yum源
  12. Python爬虫学习round01
  13. 二十天一学通C#:.NET中文件和文件夹的类
  14. CSS-Box模型--理解与整理
  15. 5.从Paxos到Zookeeper分布式一致性原理与实践---使用ZooKeeper
  16. JSP学习——Eclipse自定义JSP模板(修改默认JSP文件)
  17. WinSnap 截图工具绿色中文特别版
  18. 切换输入法半角全角(打开关闭输入法)
  19. Python Crash Course读书笔记 - 第18章:GETTING STARTED WITH DJANGO
  20. Matlab P文件 p-code 破解解析

热门文章

  1. 关于《系统集成项目管理工程师》——建筑与建筑群综合布线工程中常见的术语和符号精华汇总
  2. sql server 发布订阅_Mick的SQL基础教程 2月24日-25日
  3. cesium entity与时间轴关联(添加运动轨迹)
  4. Py修行路 python基础 (五)三元运算 字符编码 元组 集合 三级菜单优化!
  5. Windows 11禁用驱动程序强制签名的方法
  6. 微信公众号自定义分享(vue)
  7. 大数据开发、大数据分析、大数据运维主要工作各是什么?哪个好?谢谢?
  8. python 购物车报错
  9. 带你玩转新一代无服务器产品:IBM Cloud Code Engine(二)
  10. php 登录保存在哪里看,Mac_MAC如何查看使用自动登录后保存的网站软件密码,  我们在登录网站或软件时 - phpStudy...