VMware Cloud Community
dalo
Hot Shot
Hot Shot
Jump to solution

Set fixed IP in ova

I use the Ubuntu "bionic-server-cloudimg-amd64.ova" Image to deploy a VM.

If I look at the ova config with "Get-OvfConfiguration" I get the following properties:

   Common

     instance_id :

     hostname    :

     seedfrom    :

     public_keys :

     user_data   :

     password    :

   NetworkMapping

     VM_Network:

I could set successfully all the properties and import the OVA with Import-VApp.

The deployed VM uses DHCP to get a IP.

Its possible to set a static IP with the user_data, but I don't think that this is the right way. I also tried to modify the OVF XML File and pass a IP. But cloud-init seems to ignore this setting in the OS.

Is it possible to configure a Fixed IP, so that the VM starts with this designated IP? Or do I have to use "user_data" or a DHCP for this?

I want to use the stock OVA, and do this from outside.

Reply
0 Kudos
0 Solutions
4 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik, those cloud images are set up for cloud-init.

And cloud-init can use the userdata part for the customisation.
A good overview can be found in Using cloud-init for VM templating on vSphere

A deployment takes a couple of steps :

  • deploy the OVA to create the VM
  • enter the cloud-init customisation data. There are a couple of options, see
    • use GuestInfo
    • connect a customised ISO to the VM, on which you pass data to cloud-init (this will contain a customisation script in which you set a static IP)
    • other...
  • power on the VM, and the cloud-init customisation should run


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

dalo
Hot Shot
Hot Shot
Jump to solution

Thank you, I'm now a step further.

I could successfully pass a yaml style user-data File to the deployed OS, cloud-init creates the directory but I still fails with the IP assignment:

create the yaml and encode it (Networking Config Version 2 — Cloud-Init 19.1 documentation 😞

cat  user-data

#cloud-config

runcmd:

- mkdir /root/i-was-here

network:

  ethernets:

    ens192:

      addresses: [192.168.111.111/24]

base64 -w 0 user-data

I2Nsb3VkLWNvbmZpZwpydW5jbWQ6CiAtIG1rZGlyIC9yb290L2ktd2FzLWhlcmUKbmV0d29yazoKICBldGhlcm5ldHM6CiAgICBlbnMxOTI6CiAgICAgIGFkZHJlc3NlczogWzE5Mi4xNjguMTExLjExMS8yNF0KICAgICAgZGhjcDQ6IGZhbHNlCiAgdmVyc2lvbjogMgo=

Get the ova Config, modify and deploy the VM (Powercli):

$ovaConfig = Get-OvfConfiguration .\bionic-server-cloudimg-amd64.ova

$ovaConfig.Common.user_data.Value = "I2Nsb3VkLWNvbmZpZwpydW5jbWQ6CiAtIG1rZGlyIC9yb290L2ktd2FzLWhlcmUKbmV0d29yazoKICBldGhlcm5ldHM6CiAgICBlbnMxOTI6CiAgICAgIGFkZHJlc3NlczogWzE5Mi4xNjguMTExLjExMS8yNF0KICAgICAgZGhjcDQ6IGZhbHNlCiAgdmVyc2lvbjogMgo="

Import-VApp -Source .\bionic-server-cloudimg-amd64.ova -VMHost esx001 -OvfConfiguration $ovaConfig -datastore sto001 -name ubu001

The Folder gets created, but on the Network part it seems, that the clod-init fails back to default (dhcp).

I could not find any meaningful Messages in the logs of the deployed OS.

It seems that this is a Issue inside the Ubuntu OS, but maybe someone here sees my error.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect that the following from the cloud-init documentation might explain what is happening

"User-data cannot change an instance’s network configuration. In the absence of network configuration in any of the above sources , Cloud-init will write out a network configuration that will issue a DHCP request on a “first” network interface."


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

dalo
Hot Shot
Hot Shot
Jump to solution

Thank you, I really missed this part in the docs, I concentrated too much to the config section 😕

I could now workaround the Network setup with:

#cloud-config

write_files:

- encoding: base64

   content: bmV0d29yazoKIHZlcnNpb246IDIKIGV0aGVybmV0czoKICAgZW5zMTkyOgogICAgYWRkcmVzc2VzOiBbMTkyLjE2OC4xMTEuMTExLzI0XQogICAgZ2F0ZXdheTQ6IDE5Mi4xNjguMTExLjEK

   path: /etc/netplan/50-cloud-init.yaml

runcmd:

- netplan apply

The base64 encoded  "write_files" part above is:

network:

version: 2

ethernets:

   ens192:

    addresses: [192.168.111.111/24]

    gateway4: 192.168.111.1

If needed to completely disable for future network config with cloud-config a file (/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg) with the content(network: {config: disabled}) can be created too (see the original 50-cloud-init.yaml).

base64 encode the user-data and pass it to the OVA deployment:

$ovaConfig = Get-OvfConfiguration .\bionic-server-cloudimg-amd64.ova

$ovaConfig.Common.user_data.Value = "I2Nsb3VkLWNvbmZpZwp3cml0ZV9maWxlczoKIC0gZW5jb2Rpbmc6IGJhc2U2NCAKICAgY29udGVudDogYm1WMGQyOXlhem9LSUhabGNuTnBiMjQ2SURJS0lHVjBhR1Z5Ym1WMGN6b0tJQ0FnWlc1ek1Ua3lPZ29nSUNBZ1lXUmtjbVZ6YzJWek9pQmJ

NVGt5TGpFMk9DNHhNVEV1TVRFeEx6STBYUW9nSUNBZ1oyRjBaWGRoZVRRNklERTVNaTR4TmpndU1URXhMakVLIAogICBwYXRoOiAvZXRjL25ldHBsYW4vNTAtY2xvdWQtaW5pdC55YW1sCnJ1bmNtZDoKIC0gbmV0cGxhbiBhcHBseQo="

Import-VApp -Source .\bionic-server-cloudimg-amd64.ova -VMHost esx001 -OvfConfiguration $ovaConfig -datastore store001 -name myVM

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.