question

SomasundharamArjunan-2047 avatar image
0 Votes"
SomasundharamArjunan-2047 asked ·

Unable to change the Linux hostname using custom extension

I am trying to change the linux hostname using ARM Template , find my code below

{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2019-12-01",
"name": "[concat('VMName','/HostnameChange')]",
"location": "Central US",
"copy": {
"name": "HostnameCopy",
"count": 1
},
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.1",
"autoUpgradeMinorVersion": true,
"settings": {
"skipDos2Unix": false
},
"protectedSettings": {
"commandToExecute": "hostnamectl set-hostname VMName"
}
}
}

Kindly help me to resolve

azure-virtual-machines
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

vipullag-MSFT avatar image
0 Votes"
vipullag-MSFT answered ·

@SomasundharamArjunan-2047

What Linux OS you are seeing the issue?
If its Suse, it could be due to the DHCLIENT, so in your custom script run this command try

sed -i 's/DHCLIENT_SET_HOSTNAME="yes"/DHCLIENT_SET_HOSTNAME="no"/' /etc/sysconfig/network/dhcp and you may need to add reboot at the end of the script.

Can you see what hostname is being displayed for these commands hostname cat /etc/hostname and cat /var/lib/waagent/published_hostname.
From this log (waagent.log) you can see what operation is overriding the hostname change cat /var/log/waagent.log , to see if any issue with Azure Linux Agent.

One more suggestion is to grep -r at /etc and see if there are any files with old hostname, try to change them and reboot the VM.

· 2 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am trying with Redhat and Suse both OS, also trying to change the hostname via ARM template with CustomScriptExtension. find my code below

  {
       "type": "Microsoft.Compute/virtualMachines/extensions",
       "apiVersion": "2019-12-01",
       "name": "[VirtualMachineName,'/HostnameChange')]",
       "location": "[parameters('Region')]",
       "properties": {
         "publisher": "Microsoft.Compute",
         "type": "CustomScriptExtension",
         "typeHandlerVersion": "1.7",
         "autoUpgradeMinorVersion": true,
         "settings": {
           "commandToExecute": "hostnamectl set-hostname VirtualMachineName"
         }
       }
     }



0 Votes 0 · ·
vipullag-MSFT avatar image vipullag-MSFT SomasundharamArjunan-2047 ·

@SomasundharamArjunan-2047 Thanks for sharing the OS details.

Do you see any issues in the logs?

Debug and check if the Custom Script extension is being executed without any errors. Below are the log locations where you can check the details:

   /var/lib/waagent/
   /var/lib/waagent/Microsoft.Azure.Extensions.CustomScript-x
   /var/log/azure/custom-script

Also, as mentioned in the previous reply if the extension is deploying the template without any errors check for other logs to see what is causing the hostname error.





0 Votes 0 · ·