适用于 VMware 上 AL2023 的 VMware 客户机信息 cloud-init 配置
VMware 环境没有 Amazon EC2 实例元数据服务 (IMDS),因此需要一种配置 AL2023 的替代方法。这部分介绍如何使用 VMware vSphere 中可用的 seed.iso 虚拟 CD-ROM 驱动器的替代配置机制。
此配置方法使用 VMware extraconfig 机制向 cloud-init 提供配置数据。对于以下每个键,必须提供相应的 属性。keyname.encoding
以下键可提供给 VMware extraconfig 机制。
-
guestinfo.metadata -
包含
cloud-init元数据的 JSON 或 YAML -
guestinfo.userdata -
包含
cloud-config格式的cloud-init用户数据的 YAML 文档。 -
guestinfo.vendordata(可选) -
YAML 包含
cloud-init供应商数据
相应的编码属性(guestinfo.metadata.encoding、guestinfo.userdata.encoding 和 guestinfo.vendordata.encoding)可以包含:
-
base64 -
属性的内容用
base64编码。 -
gzip+base64 -
属性的内容先用
base64编码再用gzip压缩。
注意
seed.iso 方法支持一个独立的(可选的)network-config 配置文件。VMware guestinfo 在网络配置的提供方式上有所不同。更多信息在以下部分提供。
如果需要一个明确的网络配置,则应以两个 YAML 或 JSON 属性的形式将其嵌入到 metadata 中:
-
network -
包含 JSON 或 YAML 格式的编码网络配置。
-
network.encoding -
包含上述网络配置数据的编码。对于
guestinfo数据,cloud-init支持的编码是相同的:base64和gzip+base64。
例 使用 VMware vSphere govc CLI 工具通过 guestinfo 传递配置
-
按照 KVM 和 VMware 上的 Amazon Linux 2023 的 NoCloud (seed.iso) cloud-init 配置 中的说明准备
meta-data、user-data和可选的network-config配置文件。 -
将配置文件转换为 VMware
guestinfo可用的格式。# 'meta-data', `user-data` and `network-config` are the configuration # files in the same format that would be used by a NoCloud (seed.iso) # data source, read-them and convert them to VMware guestinfo # # The VM_NAME variable is assumed to be set to the name of the VM # It is assumed that the necessary govc environment (credentials etc...) are already set metadata=$(cat "meta-data") userdata=$(cat "user-data") if [ -e "network-config" ] ; then # We need to embed the network config inside the meta-data netconf=$(base64 -w0 "network-config") metadata=$(printf "%s\nnetwork: %s\nnetwork.encoding: base64" "$metadata" "$netconf") fi metadata=$(base64 -w0 <<< "$metadata") govc vm.change -vm "$VM_NAME" \ -e guestinfo.metadata="$metadata" \ -e guestinfo.metadata.encoding="base64" userdata=$(base64 -w0 <<< "$userdata") govc vm.change -vm "$VM_NAME" \ -e guestinfo.userdata="$userdata" \ -e guestinfo.userdata.encoding="base64"