您的位置:首页 > 其它

ansible之setup模块

2016-05-02 13:09 453 查看
关于ansible的setup,具体说明在http: //docs.ansible.com/ansible/setup_module.html
其实类似saltstack的grains静态信息收集,收集一些主机硬件信息或者以及其他如fqdn等等

db是我在hosts中定义的组名也可以是主机ip
[root@ansible ~]# ansible db -m setup
db | SUCCESS => {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.33.137",
"172.17.42.1"
],
"ansible_all_ipv6_addresses": [
"fe80::20c:29ff:fe14:cc24",
"fe80::3c17:8bff:fe88:6e2b"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "05/20/2014",
"ansible_bios_version": "6.00",
"ansible_cmdline": {
"KEYBOARDTYPE": "pc",
"KEYTABLE": "us",
"LANG": "en_US.UTF-8",
"SYSFONT": "latarcyrheb-sun16",
"quiet": true,
"rd_LVM_LV": "VolGroup/lv_root",
"rd_NO_DM": true,
"rd_NO_LUKS": true,
"rd_NO_MD": true,
"rhgb": true,
"ro": true,
"root": "/dev/mapper/VolGroup-lv_root"
},
"ansible_date_time": {
"date": "2016-05-02",
"day": "02",
"epoch": "1462151488",
"hour": "09",
"iso8601": "2016-05-02T01:11:28Z",
"iso8601_basic": "20160502T091128125057",
"iso8601_basic_short": "20160502T091128",
"iso8601_micro": "2016-05-02T01:11:28.125158Z",
"minute": "11",
"month": "05",
"second": "28",
"time": "09:11:28",
"tz": "CST",
"tz_offset": "+0800",
"weekday": "Monday",
"weekday_number": "1",
"weeknumber": "18",
"year": "2016"
},
"ansible_default_ipv4": {
"address": "192.168.33.137",
"alias": "eth0",
"broadcast": "192.168.33.255",
"gateway": "192.168.33.2",
"interface": "eth0",
"macaddress": "00:0c:29:14:cc:24",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.33.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": {
"sectors": "1024000",
"sectorsize": 512,
"size": "500.00 MB",
"start": "2048"
},
"sda2": {
"sectors": "103831552",
"sectorsize": 512,
"size": "49.51 GB",
"start": "1026048"
}
},
"removable": "0",
"rotational": "1",
"scheduler_mode": "cfq",
"sectors": "104857600",
"sectorsize": "512",
"size": "50.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",
"scheduler_mode": "cfq",
"sectors": "2097151",
"sectorsize": "512",
"size": "1024.00 MB",
"support_discard": "0",
"vendor": "NECVMWar"
}
},
"ansible_distribution": "CentOS",
"ansible_distribution_major_version": "6",
"ansible_distribution_release": "Final",
"ansible_distribution_version": "6.6",
"ansible_dns": {
"nameservers": [
"192.168.33.2"
],
"search": [
"localdomain"
]
},
"ansible_docker0": {
"active": true,
"device": "docker0",
"id": "8000.000000000000",
"interfaces": [],
"ipv4": {
"address": "172.17.42.1",
"broadcast": "global",
"netmask": "255.255.0.0",
"network": "172.17.0.0"
},
"ipv6": [
{
"address": "fe80::3c17:8bff:fe88:6e2b",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "3e:17:8b:88:6e:2b",
"mtu": 1500,
"promisc": false,
"stp": false,
"type": "bridge"
},
"ansible_domain": "",
"ansible_env": {
"G_BROKEN_FILENAMES": "1",
"HOME": "/root",
"LANG": "en_US.UTF-8",
"LC_ALL": "en_US.UTF-8",
"LC_MESSAGES": "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_CLIENT": "192.168.33.131 38108 22",
"SSH_CONNECTION": "192.168.33.131 38108 192.168.33.137 22",
"SSH_TTY": "/dev/pts/0",
"TERM": "xterm",
"USER": "root",
"_": "/usr/bin/python"
},
"ansible_eth0": {
"active": true,
"device": "eth0",
"ipv4": {
"address": "192.168.33.137",
"broadcast": "192.168.33.255",
"netmask": "255.255.255.0",
"network": "192.168.33.0"
},
"ipv6": [
{
"address": "fe80::20c:29ff:fe14:cc24",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "00:0c:29:14:cc:24",
"module": "e1000",
"mtu": 1500,
"pciid": "0000:02:01.0",
"promisc": false,
"type": "ether"
},
"ansible_fips": false,
"ansible_form_factor": "Other",
"ansible_fqdn": "db",
"ansible_hostname": "db",
"ansible_interfaces": [
"lo",
"docker0",
"eth0"
],
"ansible_kernel": "2.6.32-504.23.4.el6.x86_64",
"ansible_lo": {
"active": true,
"device": "lo",
"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": {
"lv_root": {
"size_g": "48.54",
"vg": "VolGroup"
},
"lv_swap": {
"size_g": "0.97",
"vg": "VolGroup"
}
},
"vgs": {
"VolGroup": {
"free_g": "0",
"num_lvs": "2",
"num_pvs": "1",
"size_g": "49.51"
}
}
},
"ansible_machine": "x86_64",
"ansible_memfree_mb": 105,
"ansible_memory_mb": {
"nocache": {
"free": 217,
"used": 265
},
"real": {
"free": 105,
"total": 482,
"used": 377
},
"swap": {
"cached": 0,
"free": 991,
"total": 991,
"used": 0
}
},
"ansible_memtotal_mb": 482,
"ansible_mounts": [
{
"device": "/dev/mapper/VolGroup-lv_root",
"fstype": "ext4",
"mount": "/",
"options": "rw",
"size_available": 44720926720,
"size_total": 51164958720,
"uuid": "ac02f356-e4ce-448b-914d-4ba34575f6a2"
},
{
"device": "/dev/sda1",
"fstype": "ext4",
"mount": "/boot",
"options": "rw",
"size_available": 421961728,
"size_total": 499355648,
"uuid": "06425d02-4d1f-49a1-afdb-8ef1dafd3334"
}
],
"ansible_nodename": "db",
"ansible_os_family": "RedHat",
"ansible_pkg_mgr": "yum",
"ansible_processor": [
"GenuineIntel",
"Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz"
],
"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 a2 b5 7d 5d 89 ea-96 fa 0b 4a 97 14 cc 24",
"ansible_product_uuid": "564DA2B5-7D5D-89EA-96FA-0B4A9714CC24",
"ansible_product_version": "None",
"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": "AAAAB3NzaC1kc3MAAACBANNbS+lp2pmFe5jHrIqbAxO0pPeuprVJVIKwnuNFzSavaoGBtK0PdtDhvuky4BJq9v2RnztCIaTohY2QqZE3hhknUAGywuAdpPGMnsWGazY6Ne70ZsobVegATk88G7e2A/pQsFLskJEjzieUtS4orAvCnAwssNJcbaCTw5EnfNfNAAAAFQCUWV2C4o0oTzBO9HfibENN7E9FCQAAAIEAhC/CKIvfxMLIbWG0nqpSmBP/aBzG+2nFKV326vDhReLJEC0cLKRggrtJdOlKClCnfVU8vmXjbjzuEDr/MF//8DbA/4kRNpjua+dZjnkrr4hbSzdQsCa1B2nzK1hioqh2Dn8rhsrZSrAwjYFcLa81p3s3+Ja02jCWt/rgBvDOLNQAAACAZ/LC5sF7jgZSLDMfrRJbEB4KgcadhpKSoISymE2+lHr9pO4lZfVG6djscA7WsF+cB5Td2or4XPeU/1IOWczaTieiFHGJ7ywioafGNbYXtrSf7z2KGbEwizGGMS4036RvA5Y3cbIT2166JAxeThaF+wb66r+AZKvRqk7kYGyoUdI=",
"ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAABIwAAAQEAuIPddB4RPpv6RoeFlxMQV8l0aZPUy/S3z8JgmVgTZAGZCtULe6YFPnqUN1FvcPrIrHDDaRZ8AthzH8fpELGU9DDQpUpvHRXlV7Q29feQ1+N5v4fGE0nCwiS+T2exnBgyIh84FTDhpL/wdielu4+PtF3ED/IPGrxEepjm/ethqzV00g9e8IpdxKaFmhGFJB2HjPjBzywz/UwUzZ1XPNNRGWO/niVxivmIQPzul0OAIddTiXLW+5ay3D5ajrsFXfbpkUUBuwxzTdlNYmOR/YUonK76LUvIoUF4WZish4XcBEpHXn2lCI6zDyj8nGVX5yUDIlRdgTcMB0EWtv2cwLVkZw==",
"ansible_swapfree_mb": 991,
"ansible_swaptotal_mb": 991,
"ansible_system": "Linux",
"ansible_system_vendor": "VMware, Inc.",
"ansible_uptime_seconds": 15909,
"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
}


setup的用法
[root@ansible ~]# ansible-doc -s setup
less 436
Copyright (C) 1984-2009 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less - name: Gathers facts about remote hosts
action: setup
fact_path              # path used for local ansible facts (*.fact) - files in this dir will be run (if executable) and
their results be added to ansible_local facts if a file is not
executable it is read. File/results format can be json or ini-
format
filter                 # if supplied, only return facts that match this shell-style (fnmatch) wildcard.


使用setup获取ip地址以及主机名使用filter过滤等等

ip地址
[root@ansible ~]# ansible db -m setup -a 'filter=ansible_default_ipv4'
db | SUCCESS => {
"ansible_facts": {
"ansible_default_ipv4": {
"address": "192.168.33.137",
"alias": "eth0",
"broadcast": "192.168.33.255",
"gateway": "192.168.33.2",
"interface": "eth0",
"macaddress": "00:0c:29:14:cc:24",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.33.0",
"type": "ether"
}
},
"changed": false
}
获取内存信息。
[root@ansible ~]# ansible db -m setup -a 'filter=ansible_memory_mb'
db | SUCCESS => {
"ansible_facts": {
"ansible_memory_mb": {
"nocache": {
"free": 217,
"used": 265
},
"real": {
"free": 101,
"total": 482,
"used": 381
},
"swap": {
"cached": 0,
"free": 991,
"total": 991,
"used": 0
}
}
},
"changed": false
}
获取主机名。。
[root@ansible ~]# ansible db -m setup -a 'filter=ansible_nodename'
db | SUCCESS => {
"ansible_facts": {
"ansible_nodename": "db"
},
"changed": false
}

ansible的setup就到这吧。那个fact_path,其实就是在本地定义一些键值对,然后指定文件路径使用.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  setup ansible