网络

通过ansible自动化部署NSX-T 2.5.1

· 4160 字 · 约 9 分钟

在安装 NSX-T 的时候,我们需要安装 nsxmgr、配置 TZ、安装 edge-node 节点等组件,而且安装这些组件的时候,需要一定安装顺序并手工安装。要成功安装 NSX-T,要我们对 NSX-T 的架构有一定的了解决。另外,在我自己的 lab 里边,需要经常搭建 NSX-T 的测试环境,每次手工安装测试环境都需要至少一天的时间,耗时耗力。那么我们有没有办法以代码的形式安装 NSX-T 呢?

Ansible 是一款运维自动化的工具,通过它可以实现 NSX-T 的自动化部署,并且代码可以重用。使用 ansible 之后,安装 NSX-T 只需 1 小时即可完成,在安装之前,我们只需将相应的参数填入到 yml 文件中即可。安装过程全部自动化。后续 NSX-T 环境出现问题,我们还可以通过 ansible 删除 NSX-T,然后再重新安装。

在 ansible 模块,本文主要介绍通过 ansible 以代码的方式安装 NSX-T 基础架构。

安装要求和环境准备

  1. 安装好 3 台 ESX 主机(当然更多台也可以)

  2. 安装 VC,并将 3 台 ESX 主机加入到 VC

  3. 安装 ubuntu linux,我安装的是 16.04.6,当然安装 centos 也可以

  4. 在 unbutu 上安装 ansible,采用以下命令

1
2
3
4
5
6
7
apt install make git make python-setuptools gcc python-dev libffi-dev libssl-dev python-packaging
apt-get install software-properties-common
apt-add-repository ppa:ansible/ansible
apt-get update
apt-get install ansible
apt-get install python-pip
pip install --upgrade pyvmomi pyvim requests
  1. 准备 NSX-T 安装包,并将它 copy 到指定的目录 /home/vmware

在 linux 中创建一个目录,/home/vmware/,把 NSX-T 2.5.1 的安装包放到这个目录下。

安装包的文件名:nsx-unified-appliance-2.5.1.0.0.15314292.ova

  1. 在 ubuntu 上安装 ovftool

下载 VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle,然后将它 cop 到 linuxe 的 home 目录下

1
2
chmod +x VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle
sudo ./VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle

查看 ovftool 版本,ovftool –version

NSX-T ansible 脚本下载

https://github.com/vmware/ansible-for-nsxt

将 ansible 自动化安装脚本下载到本地 linux 中,并且将它解压到 /root/ansible-for-nsxt-master 下,进入 examples 下,里边有两个目录,分别是 deploy_nsx_cluster 和 setup_infra,将这两个目录下的文件全部 copy 到 /root/ansible-for-nsxt-master 下,注意,一定要 copy 到 /root/ansible-for-nsxt-master/ 下,否则会出现 ansible 脚本无法执行的情况

1
2
cp /root/ansible-for-nsxt-master/examples/deploy_nsx_cluster/* /root/ansible-for-nsxt-master/
cp /root/ansible-for-nsxt-master/examples/setup_infra/* /root/ansible-for-nsxt-master/

自动化安装 NSX-Manager,并加入 VC

  1. 编辑 deploy_nsx_cluster_vars.yml
 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
# Copyright 2018 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-only
#
# Variables file for deploying NSX-T Cluster
#
{

#
# Common NSX Appliance variables
# 以下是nsx-manager的用户名和密码
"nsx_username": "admin",
"nsx_password": "VMware123456",
"validate_certs": False,

#
# OVA/OVF Information. Path can be on local file system or a HTTP URL
# nsx-manager ova的文件路径
"nsx_ova_path": "/home/vmware",
"nsx_ova": "nsx-unified-appliance-2.5.1.0.0.15314292.ova",

#
# Common network details. This assumes all NSX appliance nodes are on the
# same subnet. If there is a need to deploy NSX appliance nodes which are
# on different subnets, add node specific details in the blocks below and
# use them in the playbooks instead.
# 为nsx-manager配置子网掩码、网关、dns和ntp
"domain": "corp.local",
"netmask": "255.255.255.0",
"gateway": "192.168.110.1",
"dns_server": "192.168.110.10",
"ntp_server": "192.168.110.10",

#
# First NSX appliance node. Defined separate based on the consumption.
# Accepts both IP (IPv4) and FQDN for 'mgmt_ip'
# 部署第一个nsx-manager,在vc中显示的名称是nsxmgr-01b.corp.local
# mgmt_ip为nsx-manager的管理IP
# datacenter为在vc中显示的Datacenter,cluster为VC中显示的cluster名称
# nsx-manager这个VM要安装到哪一个datastore上,它的管理网连接到VM Network
"nsx_node1": {
"hostname": "nsxmgr-01b.corp.local",
"mgmt_ip": "192.168.110.199",
"datacenter": "Datacenter",
"cluster": "Cluster",
"datastore": "datastore1",
"portgroup": "VM Network"
},

#
# Additional nodes defined as an array so that its easier to iterate
# through them in the playbook.
# NOTE: The Datacenter/Cluster/Datastore/Network requires the vCenter MOID
# (Module Object ID) and not the name
# 如果是需要一个nsx-manager,下边的additional_nodes不需要配置。
"additional_nodes": [
{
"hostname": "mynsx-02.mylab.local",
"mgmt_ip": "10.114.200.12",
"prefix": "27",
"datacenter_moid": "datacenter-2",
"cluster_moid": "domain-c7",
"datastore_moid": "datastore-15",
"portgroup_moid": "network-16"
},
{
"hostname": "mynsx-03.mylab.local",
"mgmt_ip": "10.114.200.13",
"prefix": "27",
"datacenter_moid": "datacenter-2",
"cluster_moid": "domain-c9",
"datastore_moid": "datastore-21",
"portgroup_moid": "network-16"
}
],

#
# One or more compute managers that have to be registered with NSX
# 把VC注册到nsx-manager上,vc的名称是vcsa-01b,管理IP是192.168.110.200,密码是XXX
"compute_managers": [
{
"display_name": "vcsa-01b",
"mgmt_ip": "192.168.110.200",
"origin_type": "vCenter",
"credential_type": "UsernamePasswordLoginCredential",
"username": "administrator@vsphere.local",
"password": "VMware12"
}
]
}

如果通过 ansbile 安装 nsx-t 2.5,需要修改 01_deploy_first_node.yml,将 role 改为 NSX-Manager

1
2
3
4
# Note: In case of deploying NSX 2.5, the role should be "NSX Manager". The below
# is valid for NSX 2.4 release
# role: "nsx-manager nsx-controller"
role: "NSX Manager"
  1. 创建一个名称为 create_nsxmgr.yml 的文件,文件中包括自动执行 01_deploy_first_node.yml 和 02_configure_compute_manager.yml,文件内容如下:
1
2
3
4
root@AnsibleVM:~/ansible-for-nsxt-master# cat create_nsxmgr.yml
---
- import_playbook: 01_deploy_first_node.yml
- import_playbook: 02_configure_compute_manager.yml
  1. 执行 ansible 自动化创建 nsxmgr 的脚本文件
1
root@AnsibleVM:~/ansible-for-nsxt-master#ansible-planbook create_nsxmgr.yml -v
  1. 到 vc 中查看,已经创建了 nsxmgr-01b.corp.local,然后登录到 nsxmgr,vc 已经注册到 nsxmgr.

ansible 自动化安装 NSX 其它组件

  1. 编辑 setup_infra_vars.yml
  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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# 每台esx主机带4块网卡,vmnic0用于管理,vmnic1用于overlay,vmnic1用于vlan
# 创建两个nvds,分别是nvds-overlay和nvds-vlan,创建两个TZ,分别是overlay-TZ和VLAN-TZ
# 将部署两个edge-node,并加入edge-cluster,edge-node的eth0用于管理,fp-eth0用于overlay,fp-eth1用于vlan,将edge-node虚拟机部署在esx主机上
# Copyright 2018 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-only
#
#
# Variables file for Day-0/1 setup
# Creates the following:
# - 2 Transport Zones
# - 1 IP Pool (used by Edge)
# - 1 Transport Node Profile with 2 TZ endpoints
# - 2 Edge Transport Nodes
# - 2 ESX Host Transport Nodes
# - 1 Edge Cluster with the 2 Edge Nodes
#
{

#
# Flag to create or delete all the objects
# Accepts: 'present' to create; 'absent' to delete
#
"state": "present",

#
# Common NSX Appliance variables
#
"nsx_username": "admin",
"nsx_password": "VMware1!VMware1!",
"validate_certs": False,

#
# First NSX appliance node. Defined separate based on the consumption.
# Accepts both IP (IPv4) and FQDN for 'mgmt_ip'
#
"nsx_node1": {
"hostname": "msxmgr-01b.corp.local",
"mgmt_ip": "192.168.110.199",
"datacenter": "Datacenter",
"cluster": "Cluster",
"datastore": "datastore1",
"portgroup": "VM Network"
},

"transport_zones": [
{
"display_name": "Overlay-TZ",
"description": "NSX Configured Overlay Transport Zone",
"transport_type": "OVERLAY",
"host_switch_name": "nvds-overlay"
},
{
"display_name": "VLAN-TZ",
"description": "NSX Configured VLAN Transport Zone",
"transport_type": "VLAN",
"host_switch_name": "nvds-vlan"
}
],

# 指定TEP的地址池,网关IP地址
"ip_pools": [
{
"display_name": "TEP-IP-Pool",
"subnets": [
{
"allocation_ranges": [
{
"start": "1.1.1.201",
"end": "1.1.1.210"
}
],
"gateway_ip": "1.1.1.1",
"cidr": "1.1.1.0/24"
}
]
}
],

"transport_node_profiles": [
{
"display_name": "Compute-Profile-1",
"description": "Compute Transport Node Profile",
"host_switches": [
{
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"host_switch_name": "nvds-overlay",
"pnics": [
{
"device_name": "vmnic1",
"uplink_name": "uplink-1"
}
],
"ip_assignment_spec":
{
"resource_type": "StaticIpPoolSpec",
"ip_pool_name": "TEP-IP-Pool"
}
},
{
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"host_switch_name": "nvds-vlan",
"pnics": [
{
"device_name": "vmnic2",
"uplink_name": "uplink-1"
}
],
}
],
"transport_zone_endpoints": [
{
"transport_zone_name": "Overlay-TZ"
},
{
"transport_zone_name": "VLAN-TZ"
}
]
}
],

"transport_nodes": [
{
"display_name": "EdgeNode-01",
"description": "NSX Edge Node 01",
"host_switches": [
{
"host_switch_profiles": [
{
"name": "nsx-edge-single-nic-uplink-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"host_switch_name": "nvds-overlay",
"pnics": [
{
"device_name": "fp-eth0",
"uplink_name": "uplink-1"
}
],
"ip_assignment_spec":
{
"resource_type": "StaticIpPoolSpec",
"ip_pool_name": "TEP-IP-Pool"
}
},
{
"host_switch_profiles": [
{
"name": "nsx-edge-single-nic-uplink-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"host_switch_name": "nvds-vlan",
"pnics": [
{
"device_name": "fp-eth1",
"uplink_name": "uplink-1"
}
],
}
],
"transport_zone_endpoints": [
{
"transport_zone_name": "Overlay-TZ"
},
{
"transport_zone_name": "VLAN-TZ"
}
],
# vm_name是在nsxmgr中显示的名字,
# compute_id代于的是vc中cluster的ID,storage_id/host_id/management_network_id都可以通过https://vc-fqdn/mod中获得
# data_network_ids可以通过https://vc-fqdn/mod中获得,第一行的network-20代表要将edge-node管理口连接的VM Network,
# 第二行和第三行的network-20代表将edge-node ovelay和vlan连接的VM Network
"node_deployment_info": {
"deployment_type": "VIRTUAL_MACHINE",
"deployment_config": {
"vm_deployment_config": {
"vc_name": "vcsa-01b",
"compute_id": "domain-c7",
"storage_id": "datastore-21",
"host_id": "host-15",
"management_network_id": "network-20",
"hostname": "edgenode-01.corp.local",
"data_network_ids": [
"network-20",
"network-20",
"network-20"
# "dvportgroup-24"
],
"management_port_subnets": [
{
"ip_addresses": [ "192.168.110.204" ],
"prefix_length": 24
}
],
"default_gateway_addresses": [ "192.168.110.1" ],
"allow_ssh_root_login": true,
"enable_ssh": true,
"placement_type": "VsphereDeploymentConfig"
},
"form_factor": "MEDIUM",
"node_user_settings": {
"cli_username": "admin" ,
"root_password": "VMware123456",
"cli_password": "VMware123456",
"audit_username": "audit",
"audit_password": "VMware123456"
}
},
"resource_type": "EdgeNode",
"display_name": "EdgeNode-01"
},
},
{
"display_name": "EdgeNode-02",
"description": "NSX Edge Node 02",
"host_switches": [
{
"host_switch_profiles": [
{
"name": "nsx-edge-single-nic-uplink-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"host_switch_name": "nvds-overlay",
"pnics": [
{
"device_name": "fp-eth0",
"uplink_name": "uplink-1"
}
],
"ip_assignment_spec":
{
"resource_type": "StaticIpPoolSpec",
"ip_pool_name": "TEP-IP-Pool"
}
},
{
"host_switch_profiles": [
{
"name": "nsx-edge-single-nic-uplink-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"host_switch_name": "nvds-vlan",
"pnics": [
{
"device_name": "fp-eth1",
"uplink_name": "uplink-1"
}
],
}
],
"transport_zone_endpoints": [
{
"transport_zone_name": "Overlay-TZ"
},
{
"transport_zone_name": "VLAN-TZ"
}
],
"node_deployment_info": {
"deployment_type": "VIRTUAL_MACHINE",
"deployment_config": {
"vm_deployment_config": {
"vc_name": "vcsa-01b",
"compute_id": "domain-c7",
"storage_id": "datastore-23",
"host_id": "host-18",
"management_network_id": "network-20",
"hostname": "edgenode-02.corp.local",
"data_network_ids": [
"network-20",
"network-20",
"network-20"
],
"management_port_subnets": [
{
"ip_addresses": [ "192.168.110.205" ],
"prefix_length": 24
}
],
"default_gateway_addresses": [ "192.168.110.1" ],
"allow_ssh_root_login": true,
"enable_ssh": true,
"placement_type": "VsphereDeploymentConfig"
},
"form_factor": "MEDIUM",
"node_user_settings": {
"cli_username": "admin" ,
"root_password": "VMware123456",
"cli_password": "VMware123456",
"audit_username": "audit",
"audit_password": "VMware123456"
}
},
"resource_type": "EdgeNode",
"display_name": "EdgeNode-02"
},
},
{
"resource_type": "TransportNode",
"display_name": "esx-01b",
"description": "Host Transport Node for first ESXi host",
"host_switches": [
{
"host_switch_name": "nvds-overlay",
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"pnics": [
{
"device_name": "vmnic1",
"uplink_name": "uplink-1"
}
],
"ip_assignment_spec": {
"resource_type": "StaticIpPoolSpec",
"ip_pool_name": "TEP-IP-Pool"
}
},
{
"host_switch_name": "nvds-vlan",
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"pnics": [
{
"device_name": "vmnic2",
"uplink_name": "uplink-1"
}
],
}
],
"transport_zone_endpoints": [
{
"transport_zone_name": "Overlay-TZ"
},
{
"transport_zone_name": "VLAN-TZ"
}
],
# thumbprint通过ssh登录到每台ESX中获得,openssl x509 -in /etc/vmware/ssl/rui.crt -fingerprint -sha256 -noout
"node_deployment_info": {
"resource_type": "HostNode",
"ip_addresses": ["192.168.110.201"],
"os_type": "ESXI",
"host_credential": {
"username": "root",
"password": "VMware12",
"thumbprint": "E1:52:39:84:A9:D1:A1:13:3E:74:12:CD:B2:10:EA:B3:D9:47:5C:3C:F3:AD:45:A4:BB:3F:3F:ED:DB:52:E9:49"
}
}
},
{
"resource_type": "TransportNode",
"display_name": "esx-02b",
"description": "Host Transport Node for second ESXi host",
"host_switches": [
{
"host_switch_name": "nvds-overlay",
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"pnics": [
{
"device_name": "vmnic1",
"uplink_name": "uplink-1"
}
],
"ip_assignment_spec": {
"resource_type": "StaticIpPoolSpec",
"ip_pool_name": "TEP-IP-Pool"
}
},
{
"host_switch_name": "nvds-vlan",
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"pnics": [
{
"device_name": "vmnic2",
"uplink_name": "uplink-1"
}
],
}
],
"transport_zone_endpoints": [
{
"transport_zone_name": "Overlay-TZ"
},
{
"transport_zone_name": "VLAN-TZ"
}
],
"node_deployment_info": {
"resource_type": "HostNode",
"ip_addresses": ["192.168.110.202"],
"os_type": "ESXI",
"host_credential": {
"username": "root",
"password": "VMware12",
"thumbprint": "B1:97:F3:72:70:59:A9:6E:22:9B:8B:ED:AC:CB:82:F9:30:B3:23:FF:B0:92:1E:49:27:0B:92:ED:09:7C:36:03"
}
}
},
{
"resource_type": "TransportNode",
"display_name": "esx-03b",
"description": "Host Transport Node for third ESXi host",
"host_switches": [
{
"host_switch_name": "nvds-overlay",
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"pnics": [
{
"device_name": "vmnic1",
"uplink_name": "uplink-1"
}
],
"ip_assignment_spec": {
"resource_type": "StaticIpPoolSpec",
"ip_pool_name": "TEP-IP-Pool"
}
},
{
"host_switch_name": "nvds-vlan",
"host_switch_profiles": [
{
"name": "nsx-default-uplink-hostswitch-profile",
"type": "UplinkHostSwitchProfile"
},
{
"name": "nsx-default-nioc-hostswitch-profile",
"type": "NiocProfile"
},
{
"name": "LLDP [Send Packet Disabled]",
"type": "LldpHostSwitchProfile"
}
],
"pnics": [
{
"device_name": "vmnic2",
"uplink_name": "uplink-1"
}
],
"ip_assignment_spec": {
"resource_type": "StaticIpPoolSpec",
"ip_pool_name": "TEP-IP-Pool"
}
}
],
"transport_zone_endpoints": [
{
"transport_zone_name": "Overlay-TZ"
},
{
"transport_zone_name": "VLAN-TZ"
}
],
"node_deployment_info": {
"resource_type": "HostNode",
"ip_addresses": ["192.168.110.203"],
"os_type": "ESXI",
"host_credential": {
"username": "root",
"password": "VMware12",
"thumbprint": "A9:D8:90:C6:E8:3C:4C:44:85:42:A4:C9:47:62:D7:8C:04:01:0E:C0:7B:BA:96:F1:90:6A:AF:A7:C1:A5:BC:C5"
}
}
}
],

# cluster_profile_binding_id需要登录到nsxmgr中去查看
"edge_clusters": [
{
"display_name": "Edge-Cluster-01",
"cluster_profile_binding_id": "91bcaa06-47a1-11e4-8316-17ffc770799b",
"members": [
{
"transport_node_name": "EdgeNode-01"
},
{
"transport_node_name": "EdgeNode-02"
}
]
}
]
}
  1. 创建一个名称为 create_everything.yml 的文件,用于自动执行所有的安装工作

root@AnsibleVM:~/ansible-for-nsxt-master# cat create_everything.yml

1
2
3
4
5
6
---
- import_playbook: 01_deploy_transport_zone.yml
- import_playbook: 02_define_TEP_IP_Pools.yml
- import_playbook: 03_create_transport_node_profiles.yml
- import_playbook: 04_create_transport_nodes.yml
- import_playbook: 05_create_edge_cluster.yml
  1. 执行 ansible 脚本,创建所有的资源
1
root@AnsibleVM:~/ansible-for-nsxt-master# ansible-playbook create_everything.yml
  1. 登录 nsxmgr,验证创建的资源

部署了两个 TZ,分别是 Overlay-TZ 和 VLAN-TZ,每个 TZ 有不同的 nvds

部署了两个 edge-node 虚拟机,并将他们加入到一个 edge-cluster 中

ESX 主机变成了传输节点

总结

我们通过 ansible 自动化安装 nsxmgr,只需将相应的参数填入到 yml 文件中即可。我们可以执行 ansible-playbook 自动化安装 nsxmgr、vc 加入到 nsxmgr、加 esx 主机加入到传输节点,edge-node 自动化安装,并加入到 edge-cluster 中。