Setting Hostname Issue

I have a VM template with Ubuntu 14 on it and am trying to set the hostname when the VM is instantiated with the user input “set_hostname”. Unfortunately the VM is created with the hostname the original image had.

Here is the context for the VM once it is created:
CONTEXT = [
DISK_ID = “1”,
ETH0_CONTEXT_FORCE_IPV4 = “”,
ETH0_DNS = “”,
ETH0_GATEWAY = “”,
ETH0_GATEWAY6 = “”,
ETH0_IP = “192.168.100.11”,
ETH0_IP6 = “”,
ETH0_IP6_ULA = “”,
ETH0_MAC = “02:00:c0:a8:64:0b”,
ETH0_MASK = “”,
ETH0_MTU = “”,
ETH0_NETWORK = “”,
ETH0_SEARCH_DOMAIN = “”,
ETH0_VLAN_ID = “”,
ETH0_VROUTER_IP = “”,
ETH0_VROUTER_IP6 = “”,
ETH0_VROUTER_MANAGEMENT = “”,
NETWORK = “YES”,
SET_HOSTNAME = “LM02”,
SSH_PUBLIC_KEY = “”,
TARGET = “hda” ]

And here is the context for the VM Template it was created from:
CONTEXT = [
NETWORK = “YES”,
SET_HOSTNAME = “$SET_HOSTNAME”,
SSH_PUBLIC_KEY = “$USER[SSH_PUBLIC_KEY]” ]

Despite this the hostname is left as ‘Host01’, which was the hostname on the disk image the template uses.
I feel like this should be a fairly straightforward thing to do, but I am struggling to get this to work.
Thanks in advance.

Hi!
Are you using the Ubuntu image from the marketplace or have you created your own VM installing contextualization scripts?

You may try the latest release of contextualization packages which are available here. It contains the /etc/one-context.d/15-hostname which would set the hostname using context.

Cheers!

If you are experimenting, make sure you remove /tmp/context.sh before rebooting your VM (or ensure that it is not present in the image when you spin up the machine). If it is there, then the context script will diff against it and if there are no changes most of the scripts in /etc/one-context.d won’t run (or won’t do anything).