我正在尝试使用 ansible 从模板构建虚拟机。我需要指定 IP 地址。剧本中的所有其他配置均有效。这不是语法问题。这是一个实验室,所以我没有用于配置的 vlan。我必须使用网络名称。SystemsLab 是一个有效的标准端口组。
根据 vmware_guest 网络的 ansible 文档:
网络
“网络列表(按 NIC 的顺序)。重新配置虚拟机时不允许删除 NIC。所有参数和 VMware 对象名称均区分大小写。
每个条目都需要以下参数之一:
- name(字符串):此接口的端口组或分布式虚拟端口组的名称。指定分布式虚拟端口组时,请确保给定的 esxi_hostname 或集群与其关联。
- vlan(整数):此接口的 VLAN 编号。”
以下是我的虚拟机配置剧本条目:
- name: Create VM from template
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: lab-vmsystems-01
datacenter: Lab
name: testvm_1
template: RHEL74-IMG
folder: template
datastore: autoselect_datastore
networks:
- name: "SystemsLab"
type: static
device_type: vmxnet3
ip: 10.**.**.199
netmask: 255.255.255.0
gateway: 10.**.**.1
- dns_servers:
- 10.**.**.21
- 10.**.**.22
- domain: ****.net
这是我收到的错误。
"changed": false,
"invocation": {
"module_args": {
"annotation": null,
"cdrom": {},
"cluster": null,
"convert": null,
"customization": {},
"customization_spec": null,
"customvalues": [],
"datacenter": "Lab",
"datastore": "autoselect_datastore",
"disk": [],
"esxi_hostname": "lab-vmsystems-01",
"folder": "template",
"force": false,
"guest_id": null,
"hardware": {
"memory_mb": "1024",
"num_cpus": 1
},
"hostname": "***-vcenter-01",
"is_template": false,
"linked_clone": false,
"name": "testvm_1",
"name_match": "first",
"networks": [
{
"device_type": "vmxnet3",
"gateway": "10.**.**.1",
"ip": "10.**.**.199",
"name": "SystemsLab",
"netmask": "255.255.255.0",
"type": "static"
},
{
"dns_servers": [
"10.**.**.21",
"10.**.**.22"
]
},
{
"domain": "****.net"
}
],
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 443,
"resource_pool": null,
"snapshot_src": null,
"state": "present",
"state_change_timeout": 0,
"template": "RHEL74-IMG",
"use_instance_uuid": false,
"username": "***@***.net",
"uuid": null,
"validate_certs": false,
"vapp_properties": [],
"wait_for_customization": false,
"wait_for_ip_address": true
}
},
"msg": "Please specify at least a network name or a VLAN name under VM network list."```
C:\Program Files (x86)\VMware\VMware vSphere CLI>dcli +server lvd-vcenter-01 com vmware vcenter network list +skip-server-verification
|----------|----------|------------------|
|Network |Name |Type |
|----------|----------|------------------|
|network-31|VM Network|STANDARD_PORTGROUP|
|network-32|SystemsLab|STANDARD_PORTGROUP|
|----------|----------|------------------|
答案1
您正在创建三个网络接口:
"networks": [
{
"device_type": "vmxnet3",
"gateway": "10.**.**.1",
"ip": "10.**.**.199",
"name": "SystemsLab",
"netmask": "255.255.255.0",
"type": "static"
},
{
"dns_servers": [
"10.**.**.21",
"10.**.**.22"
]
},
{
"domain": "****.net"
}
],
删除 dns_servers 和 domain 的破折号:
- name: Create VM from template
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: lab-vmsystems-01
datacenter: Lab
name: testvm_1
template: RHEL74-IMG
folder: template
datastore: autoselect_datastore
networks:
- name: "SystemsLab"
type: static
device_type: vmxnet3
ip: 10.**.**.199
netmask: 255.255.255.0
gateway: 10.**.**.1
dns_servers:
- 10.**.**.21
- 10.**.**.22
domain: ****.net