How to customize virtual machine using Cloud-init metadata and user data in vSphere 7.0 Update 3
search cancel

How to customize virtual machine using Cloud-init metadata and user data in vSphere 7.0 Update 3

book

Article ID: 311895

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides information on how to customize virtual machine using Cloud-init metadata and user data in vSphere 7.0 Update 3.

Environment

VMware vSphere ESXi 7.0.3

Resolution

Prerequisites

  • Ensure that the vSphere version is 7.0 Update 3 or later.
  • Ensure that VMware Tools version 11.3.0 or later is installed in the guest operating system
  • 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.

 

Notes

  1. Virtual machine customizaion using Cloud-init metadata and user data is supported by the vSphere Web Services API (See vSphere Web Services SDK Programming Guide (7.0 Update 3)  ) and the 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. Furthermore:
    1. The length of metadata cannot be greater than 512 * 1024 characters.
    2. The network config in metadata can be either version 1 or version 2. Please refer to https://cloudinit.readthedocs.io/en/latest/topics/network-config.html for details.
    3. Metadata can be in JSON or YAML format.
    4. Metadata sample in JSON format:
      			{
      				"instance-id": "cloud-vm",
      				"local-hostname": "cloud-vm",
      				"network": {
      					"version":2,
      					"ethernets": {
      						"nics": {
      							"match": {
      								"name": "ens*"
      							},
      							"dhcp4": "yes"
      						}
      					}
      				}
      			}
    5. 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 the Cloud-init document for user data format: https://cloudinit.readthedocs.io/en/latest/topics/format.html
    1. The length of user data cannot be greater than 512 * 1024 characters.
    2. User data example in the Cloud-init document https://cloudinit.readthedocs.io/en/latest/topics/examples.html

 

Walkthrough

Please find the article "Guest Customization Using cloud-init" on how to customize a virtual machine using cloud-init metadata and user data using the vSphere web service API. The article is using Ubuntu 20.04 as an example.

 

Further notes

  1. 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
  2. If network config is absent, cloud-init will generate a fallback network which is DHCP usually.
  3. 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.