Prerequisites
- Ensure that vSphere version is 7.0 Update 3 or later.
- Ensure that VMware Tools version 11.3.0 or later is installed.
- Ensure that cloud-init version 21.1 or later is installed.
- Ensure that Datasource OVF (cloud-init ver < 23.1)or Datasource VMware(cloud-init ver >= 23.1)is included in cloud-init Datasource search list.
1. Customize virtual machine using Cloud-init metadata and user data is supported by vSphere Web Services API (See
vSphere Web Services SDK Programming Guide (7.0 Update 3) ) and vSphere Automation API (See
vSphere Automation API Reference ), there is no UI support for now.
2. Cloud-init metadata is a mandatory field in customization specification.
- The length of metadata cannot be greater than 512 * 1024 characters.
- The network config in metadata could be version 1 or version 2. Please refer to:
- Metadata could be in JSON or YAML format.
- Metadata sample in JSON format:
{
"instance-id": "cloud-vm",
"local-hostname": "cloud-vm",
"network": {
"version":2,
"ethernets": {
"nics": {
"match": {
"name": "ens*"
},
"dhcp4": "yes"
}
}
}
}
- Metadata sample in YAML format:
instance-id: cloud-vm
local-hostname: cloud-vm
network:
version: 2
ethernets:
nics:
match:
name: ens*
dhcp4: yes
3. Cloud-init user data is an optional field in customization specification, for details please refer to Cloud-init
document for user data format:
https://cloudinit.readthedocs.io/en/latest/topics/format.html
- The length of user data cannot be greater than 512 * 1024 characters.
- Please find user data example in Cloud-init document:
Walkthrough
Please find the "Guest Customization Using cloud-init " article on how to customize a virtual machine using cloud-init metadata and user data by vSphere web service API, it takes Ubuntu 20.04 as example.
Note:
- If you want to disable cloud-init‘s network configuration capability and rely on other methods, please disable it as in below in metadata:
network:
config: disabled
- If network config is absent, cloud-init will generate a fallback network which is DHCP usually.
- The instance id in metadata must be unique for each customization using this feature, if you want to re-customize a virtual machine using this feature, please make sure a different instance-id is specified in metadata.