vmware / photon

Minimal Linux container host
https://vmware.github.io/photon
Other
3.05k stars 697 forks source link

No static IP address is assigned to Photon VM using packer build #1010

Closed jzhang2018 closed 4 years ago

jzhang2018 commented 4 years ago

Packer 1.4.3 vsphere-iso 2.3 Photon 3 GA iso

I am trying to working on using packer to build the VM from iso. The template file looks like this:

``{ "variables": { "ks_path": "" },

"builders": [ { "type": "vsphere-iso",

"vcenter_server": "vcsas11001.mycloud.com", "username": "administrator@vsphere.local", "password": "mypassword", "insecure_connection": "true", "vm_name": "photon-3ga-1", "notes": "Build via Packer", "cluster": "VxRail-Virtual-SAN-Cluster-123456", "host": "esxas11001.mycloud.com", "datastore": "VxRail-Virtual-SAN-Datastore-123456", "folder": "MyCloudAPI VMs",

"guest_os_type": "vmwarePhoton64Guest",

"ssh_username": "root", "ssh_password": "root!23456,

"CPUs": 2, "RAM": 4096, "RAM_reserve_all": false, "network": "Management Network-123456",

"convert_to_template": false,

"disk_controller_type": "pvscsi", "disk_size": 25000, "disk_thin_provisioned": true,

"network_card": "vmxnet3",

"iso_paths": ["[VxRail-Virtual-SAN-Datastore-123456] iso/photon-minimal-3.0-58f9c74-bundle.iso"], "floppy_files": [ "{{user ks_path}}/photon_ks.cfg" ], "boot_command": ["", "vmlinuz initrd=initrd.img root=/dev/ram0 loglevel=3 ks=cdrom:/isolinux/photon_ks.cfg photon.media=cdrom", ""] } ] }

I use ISO approach to add the kickstart file photon_ks.cfg to the bundled iso. The kickstart file looks like:

{ "hostname": "photon-3ga-1", "password": { "crypted": false, "text": "mypassword", }, "disk": "/dev/sda", "partitions": [ {"mountpoint": "/", "size": 0, "filesystem": "ext4"}, {"mountpoint": "/boot", "size": 128, "filesystem": "ext4"}, {"mountpoint": "/root", "size": 128, "filesystem": "ext4"}, {"size": 128, "filesystem": "swap"} ],

"packagelist_file": "packages_minimal.json",
"additional_packages": ["vim"],
"postinstall": [
                    "#!/bin/sh",
                    "echo \"Hello World\" > /etc/postinstall"
               ],
"install_linux_esx": false,
"network": {
   "type": "static",
   "ip_addr": "10.60.39.129",
   "netmask": "255.255.255.0",
   "gateway": "10.60.39.1",
   "nameserver": "69.252.80.80"

} }

Here I expect the new VM photon-3ga-1 will have the static ip address 10.60.39.129 assigned to it. But it does not. The ip addr shows the interface eth0 with the machine address (see attched screenshot). Also I can't find any way to specify the ip address is for eth0 in above two configurations.

Thanks,

J static-ip

jzhang2018 commented 4 years ago

I have confirmed that I have to use the release of photon-3.0-58f9c74 (released on Feb 7, 2020) and it si working as expected. This network feature was added in Feb 2020 according to https://github.com/vmware/photon/issues/830.

J

sidcha commented 4 years ago

@jzhang2018, There is also an issue in your photon_ks.cfg: "text": "mypassword", has an extra , in it. Please use some json validator such as https://jsonlint.com/ and then retry packer.

image

jzhang2018 commented 4 years ago

Thanks cbsiddharth for your reply. The original ks file is correct without the extra ','. I had to change mask the password for obvious reason in order to post it out. Sorry about that :-(

The true reason is that the network implementation was indeed released in Feb 2020 so I switched to use the latest Photon and it works as expected.