In this article, you will learn how to customize a VM using cloud-init in a VMware Cloud Director environment.
If you are deploying a VM from a GleSYS template in VMware Cloud Director, then follow the instructions outlined in this document.
However, if you are deploying a VM from a custom-built template, then the steps outlined here do not apply, and you can continue using existing workflows for customization.
Historically, VMs deployed from a GleSYS template in VMware Cloud Director have been customized using the vmware-imc method, the default method supported in the platform.
The vmware-imc method leverages customization scripts bundled with VMware Cloud Director, which are copied onto the guest operating system and then executed by the vmtools service running in the guest.
From now on, VMs deployed from a GleSYS template in VMware Cloud Director will be customized using cloud-init.
The cloud-init method has become the de-facto industry standard for customizing VMs in the cloud. In a VMware environment, the cloud-init configuration data supplied to a VM is read using vmtools. The cloud-init service running in the guest then customizes the guest operating system according to that configuration.
There are many benefits to using the cloud-init method over the vmware-imc method:
The following steps apply to all GleSYS templates in VMware Cloud Director.
In the top right corner of the navigation bar, click your user name, select User preferences -> API Tokens, and click New.
Enter a Name for the token, and click Create. The generated API token appears. You must copy the token because it appears only once.
The metadata file is a plain-text file formatted as YAML, where you can define the hostname, instance id, and network configuration of your VM.
metadata.yaml
file on your local machine and paste the following configuration:instance-id: demo.example.com # a unique identifier or UUID for the instance
local-hostname: demo.example.com # replace with your own FQDN
network:
version: 2
ethernets:
ens192:
dhcp4: yes
The userdata file is a plain-text file formatted as YAML, where you can define many options to customize your VM, including options to create user accounts, install software packages, execute commands, and create files.
userdata.yaml
file on your local machine and paste the following configuration:#cloud-config
users:
- name: demo
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: true
ssh_authorized_keys:
- # Paste your public SSH key here
manage_etc_hosts: true
Unfortunately, supplying the cloud-init configuration in the New VM wizard is not currently possible. Therefore, an additional step is required to provide the cloud-init configuration using the VMware Cloud Director API.
set_vcd_vm_extraconfig
binary, which you can download from GitHub:export METADATA=$(gzip -c9 <metadata.yaml | { base64 -w0 2>/dev/null || base64; })
export USERDATA=$(gzip -c9 <userdata.yaml | { base64 -w0 2>/dev/null || base64; })
./set_vcd_vm_extraconfig \
-url vcd.dc-####.glesys.net \
-token ABC12345678 \
-org vdo-##### \
-vdc vdc-##### \
-vm demo \
-e guestinfo.metadata="${METADATA}" \
-e guestinfo.metadata.encoding="gzip+base64" \
-e guestinfo.userdata="${USERDATA}" \
-e guestinfo.userdata.encoding="gzip+base64"
The above command assumes your local machine is running Linux/macOS. If your local machine is running Windows, you can run the following command in PowerShell:
$metadata = [convert]::ToBase64String((Get-Content -path "metadata.yaml" -Encoding byte))
$userdata = [convert]::ToBase64String((Get-Content -path "userdata.yaml" -Encoding byte))
.\set_vcd_vm_extraconfig.exe `
-url vcd.dc-####.glesys.net `
-token ABC12345678 `
-org vdo-##### `
-vdc vdc-##### `
-vm demo `
-e guestinfo.metadata="$metadata" `
-e guestinfo.metadata.encoding="base64" `
-e guestinfo.userdata="$userdata" `
-e guestinfo.userdata.encoding="base64"
You should now be able to SSH to your VM and verify that cloud-init has customized the instance according to the configuration specified in metadata and userdata.
As mentioned, all the steps outlined in this article apply to both Linux and Windows-based GleSYS templates.
However, there is a difference regarding the contents of the userdata file when comparing Windows and Linux deployments that is worth highlighting.
Here is a sample userdata.yaml
file for Windows-based VMs:
#cloud-config
users:
- name: Administrator
no_create_home: True
inactive: True
- name: demo
groups: Administrators
passwd: passw0rdIsPlainText
Please be aware that user passwords are specified in plaintext in the userdata file. The userdata configuration is concealed on the VM after creation as a security measure. However, we recommend changing the user password in the VM after its creation to ensure maximum security.
cloud-init - Official Documentation
cloud-init - Userdata Examples
cloudbase-init (cloud-init equivalent for Windows) - Official Documentation
cloudbase-init (cloud-init equivalent for Windows) - Userdata Examples
Kontakta oss gärna för mer information. Vi hjälper dig att komma fram till den bästa lösningen för dina behov.