We’re using Rancher for provisioning k8s cluster nodes using their vSphere integration which works great. The nodes are customized by using cloud-init through cloud-config directives and everything works as advertized EXCEPT one small but, for us, very important part.
The base configuration is based on a CentOS7 7.7.1908 VM adapted for our needs, which has been converted into a template. In Rancher we have created something they call a “node template” which describes the various settings that should be assigned to the provisioned node(s). Here we also provide the cloud-config mentioned earlier which is mounted as an .iso file during provisioning.
Now, what I’d like to accomplish is to be able to pass the provisioned VM name (as seen in vCenter for example) to cloud-init so where able to set the static hostname. For us this is important because we request a specific IP based on the sent hostname to the DHCP server. Although the hostname is correctly set by the “Rancher Agent” later in the provisioning phase, we have already acquired an IP based on the VM template’s hostname (which might be template-centos-7-7-1908)!
I’ve found a workaround which schedules (using “at”) “dhclient -r; systemctl restart network …” five minutes after the cloud-init process finishes. It works but with a major drawback – we end up with “ghost IP allocations” dangling from the initial hostname which will, eventually, vanish *but* we might end up in a bad situation if we ever need to re-provision a number of nodes!
So what I would like to be able to do is to inject the given VM’s name into the cloud-init process so we may issue, say, “hostnamectl set-hostname $VM_NAME” where $VM_NAME is the injected variable. Is there any VMware tools/cloud-init thingy or the like invented somewhere which would help me accomplish this?
MANY thanks in advance!!!!!!!