When deploying to vSphere in Cloud Assembly, you can assign a static IP address but must take care not to introduce conflicts between cloudConfig initialization commands and customization specifications.
Sample designs
The following designs safely apply a static IP address without any conflict between cloud template initialization commands and customization specifications. All contain the assignment: static
network setting.
Design | Sample Cloud Template Code |
---|---|
Assign a static IP address to a Linux machine that has no cloud-init code |
resources: wpnet: type: Cloud.Network properties: name: wpnet networkType: public constraints: - tag: sqa DBTier: type: Cloud.vSphere.Machine properties: flavor: small image: linux-template networks: - name: '${wpnet.name}' assignment: static network: '${resource.wpnet.id}' |
Assign a static IP address to a Linux machine with cloud-init code that doesn't contain network assignment commands. NOTE: The vSphere customization spec is applied whether you set the customizeGuestOs property to true or omit the customizeGuestOs property. |
Ubuntu sample resources: wpnet: type: Cloud.Network properties: name: wpnet networkType: public constraints: - tag: sqa DBTier: type: Cloud.vSphere.Machine properties: flavor: small image: ubuntu-template customizeGuestOs: true cloudConfig: | #cloud-config ssh_pwauth: yes chpasswd: list: | root:Pa$$w0rd expire: false write_files: - path: /tmpFile.txt content: | ${resource.wpnet.dns} runcmd: - hostnamectl set-hostname --pretty ${self.resourceName} - touch /etc/cloud/cloud-init.disabled networks: - name: '${wpnet.name}' assignment: static network: '${resource.wpnet.id}' CentOS sample resources: wpnet: type: Cloud.Network properties: name: wpnet networkType: public constraints: - tag: sqa DBTier: type: Cloud.vSphere.Machine properties: flavor: small image: centos-template customizeGuestOs: true cloudConfig: | #cloud-config write_files: - path: /test.txt content: | deploying in power off. then rebooting. networks: - name: '${wpnet.name}' assignment: static network: '${resource.wpnet.id}' |
Assign a static IP address to a Linux machine with cloud-init code that contains network assignment commands. The customizeGuestOs property must be false. |
Ubuntu sample resources: wpnet: type: Cloud.Network properties: name: wpnet networkType: public constraints: - tag: sqa DBTier: type: Cloud.vSphere.Machine properties: flavor: small image: ubuntu-template customizeGuestOs: false cloudConfig: | #cloud-config write_files: - path: /etc/netplan/99-installer-config.yaml content: | network: version: 2 renderer: networkd ethernets: ens160: addresses: - ${resource.DBTier.networks[0].address}/${resource.wpnet.prefixLength} gateway4: ${resource.wpnet.gateway} nameservers: search: ${resource.wpnet.dnsSearchDomains} addresses: ${resource.wpnet.dns} runcmd: - netplan apply - hostnamectl set-hostname --pretty ${self.resourceName} - touch /etc/cloud/cloud-init.disabled networks: - name: '${wpnet.name}' assignment: static network: '${resource.wpnet.id}' CentOS sample resources: wpnet: type: Cloud.Network properties: name: wpnet networkType: public constraints: - tag: sqa DBTier: type: Cloud.vSphere.Machine properties: flavor: small image: centos-template customizeGuestOs: false cloudConfig: | #cloud-config ssh_pwauth: yes chpasswd: list: | root:VMware1! expire: false runcmd: - nmcli con add type ethernet con-name 'custom ens192' ifname ens192 ip4 ${self.networks[0].address}/${resource.wpnet.prefixLength} gw4 ${resource.wpnet.gateway} - nmcli con mod 'custom ens192' ipv4.dns "${join(resource.wpnet.dns,' ')}" - nmcli con mod 'custom ens192' ipv4.dns-search "${join(resource.wpnet.dnsSearchDomains,',')}" - nmcli con down 'System ens192' ; nmcli con up 'custom ens192' - nmcli con del 'System ens192' - hostnamectl set-hostname --static `dig -x ${self.networks[0].address} +short | cut -d "." -f 1` - hostnamectl set-hostname --pretty ${self.resourceName} - touch /etc/cloud/cloud-init.disabled networks: - name: '${wpnet.name}' assignment: static network: '${resource.wpnet.id}' |
When basing the deployment on a referenced image, assign a static IP address to a Linux machine with cloud-init code that contains network assignment commands. The customizeGuestOs property must be false. In addition, the cloud template must not include the ovfProperties property, which blocks customization. |
resources: wpnet: type: Cloud.Network properties: name: wpnet networkType: public constraints: - tag: sqa DBTier: type: Cloud.vSphere.Machine properties: flavor: small imageRef: 'https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.ova' customizeGuestOs: false cloudConfig: | #cloud-config ssh_pwauth: yes chpasswd: list: | root:Pa$$w0rd ubuntu:Pa$$w0rd expire: false write_files: - path: /etc/netplan/99-netcfg-vrac.yaml content: | network: version: 2 renderer: networkd ethernets: ens192: dhcp4: no dhcp6: no addresses: - ${resource.DBTier.networks[0].address}/${resource.wpnet.prefixLength} gateway4: ${resource.wpnet.gateway} nameservers: search: ${resource.wpnet.dnsSearchDomains} addresses: ${resource.wpnet.dns} runcmd: - netplan apply - hostnamectl set-hostname --pretty ${self.resourceName} - touch /etc/cloud/cloud-init.disabled networks: - name: '${wpnet.name}' assignment: static network: '${resource.wpnet.id}' |
Designs that won't work or might produce unwanted results
- The cloud-init code doesn't contain network assignment commands, and the customizeGuestOs property is false.
Neither initialization commands nor customization spec are present to configure network settings.
- The cloud-init code doesn't contain network assignment commands, and the ovfProperties property is set.
Initialization commands aren't present, but ovfProperties blocked the customization spec.
- The cloud-init code contains network assignment commands, and the customizeGuestOs property is missing or set to true.
Application of the customization spec conflicts with initialization commands.
Other workarounds for cloud-init and customization specs
When deploying to vSphere, you can also customize an image to work around cloud-init and customization spec conflicts. See the following external repository for more information.