I want to deploy an Azure Ubuntu 18.04-LTS VM with a custom data file during an automation test, using tmplate.json and parameters.json files.
Although, the VM was deployed successfully, It seem that the custom data execution have failed and I do not understand why…
According to this link, cloud-init is available in the image that I use.
My template.json file contain:
"parameters": { ... "customData": { "type": "string" } ... }, "resources": [ ... { "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2020-06-01", "name": "[parameters('virtualMachineName')]", "location": "[parameters('location')]", "dependsOn": [ "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]" ], "properties": { ... "osProfile": { "computerName": "[parameters('virtualMachineComputerName')]", "adminUsername": "[parameters('adminUsername')]", "linuxConfiguration": { "disablePasswordAuthentication": true, "ssh": { "publicKeys": [ { "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]", "keyData": "[parameters('adminPublicKey')]" } ] } }, "customData": "[parameters('customData')]" }, ... } ]
Also, I have a parameters.json file which contain:
"parameters": { ... "customData": { "value": "I2Nsb3VkLWNvbmZpZ1xucGFja2FnZV91cGdyYWRlOiB0cnVlXG5wYWNrYWdlczpcbiAgLSBpcGVyZlxuICAtIHRjcHJlcGxheVxuICAtIG5ldHBlcmY=" } }
The value is YAML base64 encoded, and it’s decoded text is:
#cloud-confignpackage_upgrade: truenpackages:n - iperfn - tcpreplayn - netperf
(*) the above template.json and parameters.json files are partial – I omitted what seems to be not related to my problem.
I also checked the file /var/log/waagent.log and I did not found anything suspicious..
However, after I deployed the ubuntu VM manually and pasted the above YAML in the custom data section (in the advance setting page) every worked fine (‘iperf’, ‘netperf’ and ‘tcpreplay’ commands were found)
Any help will be appreciated!!
Advertisement
Answer
According to my experience, the problem is that the value for the custom data is not right. I check the VM that the cloud-init provision successfully, the code does not match yours. You can check the file /var/lib/waagent/ovf-env.xml
yourself. Do not change the text yourself into a string. You can encode the text online.