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.x

Resolution

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.
  1. The length of metadata cannot be greater than 512 * 1024 characters.
  2. The network config in metadata could be version 1 or version 2. Please refer to:
  1. Metadata could be in JSON or YAML format.
  2. Metadata sample in JSON format:
     {
        "instance-id": "cloud-vm",
        "local-hostname": "cloud-vm",
        "network": {
           "version":2,
           "ethernets": {
              "nics": {
                 "match": {
                    "name": "ens*"
                 },
                 "dhcp4": "yes"
              }
           }
        }
     }
  1. 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
  1. The length of user data cannot be greater than 512 * 1024 characters.
  2. 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:
  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
  1. If network config is absent, cloud-init will generate a fallback network which is DHCP usually.
  2. 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.