Problem: I am creating a host in Vsphere using template from foreman. I want that new host to take a IP provided by me while provisioning instead from DHCP server
Expected outcome:IP assigned while provisioning and the IP of new VM spawned from image should be same
@sanketshirode You say building a host in Vsphere, are you using Foreman to do the VM creation or using something like vRealize? If you are using Foreman, in the networking tab during host create, you should be able to specify an IP as an override even if you are using DHCP.
I tried hardcoding IP when provisioning under interfaces tab but the spawned VM gets different IP from DHCP.
As i am trying image based provisioning, the IP mentioned by me while provisioning and one acquired by the newly provision host is different. Due to which i’m unable to run finish template for the new host as SSH fails.
That is not going to work, unless the DHCP is managed by Foreman. You can’t get Foreman finish script working unless the IP address provided in Foreman is actually assigned to the VM.
You make sure that the DHCP which is managing the VM is managed by Foreman, in that case you have set your Subnet IPAM to DHCP and Foreman will create the record for you. You can either accept what Foreman offers you as the next available IP address, or put your own IP. As long as it falls into the IP pool, it will work.
Note it cannot work the other way around when DHCP is not managed by Foreman, in this case it is tempting to think you need to make sure the DHCP server assigns the VM some IP address (apparently someone/something need to create reservation for the MAC address of the VM) and then you enter the IP address into Foreman. That’s a little chicken-and-egg problem, you need to enter the IP address before the VM is actually created, so you can’t see the MAC address in advance.
So AFAIK finish script will only work if DHCP server is under Foreman’s control, or you make sure somehow that IP address entered into Foreman during VM creation is correct.
Alternatively, you can use seed scripts (user data template), there are some limitations tho on how to use these in VMWare environment.
User data works via cloud-init which must be embedded on the image/template. Also, this only works with clouds, for oVirt/RHEV/VMWare there are some limitations, check product documentation.