文章目录
setup 模块采集系统信息
在Ansible之常用模块中我们简单的介绍了这个模块,但这个模块的使用跟其他模块不太一样,主要是与自定义模块配合使用的,所以放在这里来讲。
facts 组件
在讲 setup 模块之前我们先来讲讲 facts 组件:这个组件是用来收集被管理节点信息的,使用 setup 模块可以获取这些信息,facts 收集的数据是 json 格式的,其内任意一项都可以当作变量被直接应用(如在 playbook、Jinja2 模板中)。
ansible_manager ~ > ansible webservers -m setup
192.168.159.131 | SUCCESS => {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.159.131"
],
"ansible_all_ipv6_addresses": [
"fe80::e68f:2f9d:64c4:eaf"
],
"ansible_apparmor": {
"status": "disabled"
},
"ansible_architecture": "x86_64",
"ansible_bios_date": "07/29/2019",
"ansible_bios_version": "6.00",
"ansible_cmdline": {
"BOOT_IMAGE": "/vmlinuz-3.10.0-1062.12.1.el7.x86_64",
"LANG": "zh_CN.UTF-8",
"quiet": true,
"rhgb": true,
"ro": true,
"root": "UUID=9102522f-d3d9-40a4-b8ab-ea22947588db"
},
"ansible_date_time": {
"date": "2020-03-26",
"day": "26",
"epoch": "1585221115",
"hour": "19",
"iso8601": "2020-03-26T11:11:55Z",
"iso8601_basic": "20200326T191155513355",
"iso8601_basic_short": "20200326T191155",
"iso8601_micro": "2020-03-26T11:11:55.513445Z",
"minute": "11",
"month": "03",
"second": "55",
"time": "19:11:55",
"tz": "CST",
"tz_offset": "+0800",
"weekday": "星期四",
"weekday_number": "4",
"weeknumber": "12",
"year": "2020"
},
"ansible_default_ipv4": {
"address": "192.168.159.131",
"alias": "ens33",
"broadcast": "192.168.159.255",
"gateway": "192.168.159.2",
"interface": "ens33",
"macaddress": "00:0c:29:1e:c8:6c",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.159.0",
"type": "ether"
},
"ansible_default_ipv6": {
},
"ansible_device_links": {
"ids": {
"sr0": [
"ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001"
]
},
"labels": {
"sr0": [
"CentOS\\x207\\x20x86_64"
]
},
"masters": {
},
"uuids": {
"sda1": [
"35ae303e-6bb5-4109-a5bc-9369f9f0a55d"
],
"sda2": [
"9102522f-d3d9-40a4-b8ab-ea22947588db"
],
"sda3": [
"f65b116d-2e5c-467c-8189-4d80543e8ae4"
],
"sr0": [
"2017-09-05-14-14-50-00"
]
}
},
"ansible_devices": {
"sda": {
"holders": [],
"host": "",
"links": {
"ids": [],
"labels": [],
"masters": [],
"uuids": []
},
"model": "VMware Virtual S",
"partitions": {
"sda1": {
"holders": [],
"links": {
"ids": [],
"labels": [],
"masters": [],
"uuids": [
"35ae303e-6bb5-4109-a5bc-9369f9f0a55d"
]
},
"sectors": "409600",
"sectorsize": 512,
"size": "200.00 MB",
"start": "2048",
"uuid": "35ae303e-6bb5-4109-a5bc-9369f9f0a55d"
},
"sda2": {
"holders": [],
"links": {
"ids": [],
"labels": [],
"masters": [],
"uuids": [
"9102522f-d3d9-40a4-b8ab-ea22947588db"
]
},
"sectors": "22648832",
"sectorsize": 512,
"size": "10.80 GB",
"start": "411648",
"uuid": "9102522f-d3d9-40a4-b8ab-ea22947588db"
},
"sda3": {
"holders": [],
"links": {
"ids": [],
"labels": [],
"masters": [],
"uuids": [
"f65b116d-2e5c-467c-8189-4d80543e8ae4"
]
},
"sectors": "4194304",
"sectorsize": 512,
"size": "2.00 GB",
"start": "23060480",
"uuid": "f65b116d-2e5c-467c-8189-4d80543e8ae4"
}
},
"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": "",
"links": {
"ids": [
"ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001"
],
"labels": [
"CentOS\\x207\\x20x86_64"
],
"masters": [],
"uuids": [
"2017-09-05-14-14-50-00"
]
},
"model": "VMware IDE CDR10",
"partitions": {
},
"removable": "1",
"rotational": "1",
"sas_address": null,
"sas_device_handle": null,
"scheduler_mode": "deadline",
"sectors": "1622016",
"sectorsize": "2048",
"size": "792.00 MB",
"support_discard": "0",
"vendor": "NECVMWar",
"virtual"