知识点:ping模块,用于确认和对象机器之间是否能够ping通,正常情况会返回pong
知识点:setup模块,用于收集对象机器的基本设定信息。
ping使用实例
[root@host31 ansible]# ansible host32 -m pinghost32 | SUCCESS => { "changed": false, "ping": "pong"}[root@host31 ansible]#
- 1
- 2
- 3
- 4
- 5
- 6
setup使用实例
不用option的情况会输出所有相关的对象机器的facts
[root@host31 ~]# ansible host32 -m setuphost32 | SUCCESS => { "ansible_facts": { "ansible_all_ipv4_addresses": [ "192.168.122.1", "172.16.96.1", "172.16.96.0", "192.168.32.32" ], "ansible_all_ipv6_addresses": [ "fe80::20:56ff:fe8a:59b", "fe80::20c:29ff:febe:1cff" ], "ansible_architecture": "x86_64", "ansible_bios_date": "07/02/2015", "ansible_bios_version": "6.00", "ansible_cmdline": { "BOOT_IMAGE": "/vmlinuz-3.10.0-327.el7.x86_64", "LANG": "en_US.UTF-8", "quiet": true, "rd.lvm.lv": "centos/swap", "rhgb": true, "ro": true, "root": "/dev/mapper/centos-root" }, "ansible_date_time": { "date": "2016-07-30", "day": "30", "epoch": "1469884080", "hour": "09", "iso8601": "2016-07-30T13:08:00Z", "iso8601_basic": "20160730T090800352254", "iso8601_basic_short": "20160730T090800", "iso8601_micro": "2016-07-30T13:08:00.352338Z", "minute": "08", "month": "07", "second": "00", "time": "09:08:00", "tz": "EDT", "tz_offset": "-0400", "weekday": "Saturday", "weekday_number": "6", "weeknumber": "30", "year": "2016" }, "ansible_default_ipv4": { "address": "192.168.32.32", "alias": "eno16777736", "broadcast": "192.168.32.255", "gateway": "192.168.32.2", "interface": "eno16777736", "macaddress": "00:0c:29:be:1c:ff", "mtu": 1500, "netmask": "255.255.255.0", "network": "192.168.32.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": "19945472", "sectorsize": 512, "size": "9.51 GB", "start": "1026048" } }, "removable": "0", "rotational": "1", "sas_address": null, "sas_device_handle": null, "scheduler_mode": "deadline", "sectors": "20971520", "sectorsize": "512", "size": "10.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.2.1511", "ansible_dns": { "nameservers": [ "8.8.4.4" ] }, "ansible_docker0": { "active": false, "device": "docker0", "id": "8000.02425613a4da", "interfaces": [], "ipv4": { "address": "172.16.96.1", "broadcast": "global", "netmask": "255.255.255.0", "network": "172.16.96.0" }, "macaddress": "02:42:56:13:a4:da", "mtu": 1500, "promisc": false, "stp": false, "type": "bridge" }, "ansible_domain": "", "ansible_eno16777736": { "active": true, "device": "eno16777736", "ipv4": { "address": "192.168.32.32", "broadcast": "192.168.32.255", "netmask": "255.255.255.0", "network": "192.168.32.0" }, "ipv6": [ { "address": "fe80::20c:29ff:febe:1cff", "prefix": "64", "scope": "link" } ], "macaddress": "00:0c:29:be:1c:ff", "module": "e1000", "mtu": 1500, "pciid": "0000:02:01.0", "promisc": false, "type": "ether" }, "ansible_env": { "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:/usr/sbin:/usr/bin", "PWD": "/root", "PYTHONPATH": "", "SELINUX_LEVEL_REQUESTED": "", "SELINUX_ROLE_REQUESTED": "", "SELINUX_USE_CURRENT_RANGE": "", "SHELL": "/bin/bash", "SHLVL": "2", "SSH_CLIENT": "192.168.32.31 48444 22", "SSH_CONNECTION": "192.168.32.31 48444 192.168.32.32 22", "SSH_TTY": "/dev/pts/0", "TERM": "xterm", "USER": "root", "XDG_RUNTIME_DIR": "/run/user/0", "XDG_SESSION_ID": "150", "_": "/usr/bin/python" }, "ansible_fips": false, "ansible_flannel.1": { "active": true, "device": "flannel.1", "ipv4": { "address": "172.16.96.0", "broadcast": "global", "netmask": "255.240.0.0", "network": "172.16.0.0" }, "ipv6": [ { "address": "fe80::20:56ff:fe8a:59b", "prefix": "64", "scope": "link" } ], "macaddress": "02:20:56:8a:05:9b", "mtu": 1450, "promisc": false, "type": "ether" }, "ansible_form_factor": "Other", "ansible_fqdn": "host32", "ansible_gather_subset": [ "hardware", "network", "virtual" ], "ansible_hostname": "host32", "ansible_interfaces": [ "docker0", "lo", "flannel.1", "eno16777736", "virbr0-nic", "virbr0" ], "ansible_kernel": "3.10.0-327.el7.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": { "docker-poolmeta": { "size_g": "0.01", "vg": "centos" }, "root": { "size_g": "8.47", "vg": "centos" }, "swap": { "size_g": "1.00", "vg": "centos" } }, "vgs": { "centos": { "free_g": "0.03", "num_lvs": "3", "num_pvs": "1", "size_g": "9.51" } } }, "ansible_machine": "x86_64", "ansible_machine_id": "c7e3ea1209604e87aaad01ff134e9e3b", "ansible_memfree_mb": 111, "ansible_memory_mb": { "nocache": { "free": 1103, "used": 882 }, "real": { "free": 111, "total": 1985, "used": 1874 }, "swap": { "cached": 0, "free": 1023, "total": 1023, "used": 0 } }, "ansible_memtotal_mb": 1985, "ansible_mounts": [ { "device": "/dev/mapper/centos-root", "fstype": "xfs", "mount": "/", "options": "rw,seclabel,relatime,attr2,inode64,noquota", "size_available": 4573728768, "size_total": 9082765312, "uuid": "badd077b-0a3e-40ee-99f7-dab08665cee5" }, { "device": "/dev/sda1", "fstype": "xfs", "mount": "/boot", "options": "rw,seclabel,relatime,attr2,inode64,noquota", "size_available": 374276096, "size_total": 520794112, "uuid": "15d4410f-795d-4e37-8731-1d104b525b3f" } ], "ansible_nodename": "host32", "ansible_os_family": "RedHat", "ansible_pkg_mgr": "yum", "ansible_processor": [ "GenuineIntel", "Intel(R) Core(TM) i7-4710MQ 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 d6 c3 21 f3 9c bf-0b 6b e1 a7 ee be 1c ff", "ansible_product_uuid": "564DD6C3-21F3-9CBF-0B6B-E1A7EEBE1CFF", "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_selinux": { "config_mode": "permissive", "mode": "permissive", "policyvers": 28, "status": "enabled", "type": "targeted" }, "ansible_service_mgr": "systemd", "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGSR3DThz2RLoPAZKtY6jIFJun355SHQlrY3ATc4nEmERiscRviOWZaLRL1d6NwGZxFAIrpHqQ8tYr2VGZIcYPk=", "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAIBkXu5pAOmK96YZJmws0QruTPUtf8CAaUZ0d5iPp6C1Q", "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDjiG6UaDQakAGpi0RMarJwdzv6XBayhLFL0+uwzqrS0LdC4PMyoqU9rQQrpugXht0JKCbRs/pi4/bNt1x3YrWjkpIGUE88jgq9JSnzPkcWh1ffpCFih7Tr4PZkVp2NeeyuJXgvxiXVw34ZpZ8Kcl0wOAyyYGJNbIS38zAl3SmFTbrEEZCQhXxCA/m5GUYkjnoJxXezeE3uAdQ5vVU/k20tfPEpEeYR9RPaCgEUteHh9fKIHD8f4kXaiD3vT2tG9JHU35V3vI/EkJLtKBsUAXDgUaydOYrmn9xJb92kWFMTug5aBllwuf5O1Ws98xOzPANp4EWUrbAzLf/MFhzxBIwH", "ansible_swapfree_mb": 1023, "ansible_swaptotal_mb": 1023, "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": 56290, "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", "id": "8000.000000000000", "interfaces": [], "ipv4": { "address": "192.168.122.1", "broadcast": "192.168.122.255", "netmask": "255.255.255.0", "network": "192.168.122.0" }, "mtu": 1500, "promisc": false, "stp": true, "type": "bridge" }, "ansible_virbr0_nic": { "active": false, "device": "virbr0-nic", "macaddress": "52:54:00:6b:d9:6c", "mtu": 1500, "promisc": false, "type": "ether" }, "ansible_virtualization_role": "guest", "ansible_virtualization_type": "VMware", "module_setup": true }, "changed": false}[root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411
- 412
- 413
- 414
- 415
- 416
- 417
- 418
- 419
- 420
- 421
- 422
- 423
- 424
- 425
- 426
- 427
- 428
- 429
- 430
- 431
- 432
- 433
- 434
setup常用Option:filter
比如收集对象机器的环境变量信息
[root@host31 ~]# ansible host32 -m setup -a "filter=ansible_env"host32 | SUCCESS => { "ansible_facts": { "ansible_env": { "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:/usr/sbin:/usr/bin", "PWD": "/root", "PYTHONPATH": "", "SELINUX_LEVEL_REQUESTED": "", "SELINUX_ROLE_REQUESTED": "", "SELINUX_USE_CURRENT_RANGE": "", "SHELL": "/bin/bash", "SHLVL": "2", "SSH_CLIENT": "192.168.32.31 48482 22", "SSH_CONNECTION": "192.168.32.31 48482 192.168.32.32 22", "SSH_TTY": "/dev/pts/0", "TERM": "xterm", "USER": "root", "XDG_RUNTIME_DIR": "/run/user/0", "XDG_SESSION_ID": "151", "_": "/usr/bin/python" } }, "changed": false}[root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow