I am creating a linux vm using a custom image from an shared image gallery using java sdk.
virtualMachine = azure.virtualMachines()
.define(linuxVMName)
.withRegion(location)
.withExistingResourceGroup(resourceGroup)
.withExistingPrimaryNetworkInterface(networkInterface)
.withLinuxCustomImage(customImageUrl)
.withRootUsername(username)
.withRootPassword(password)
.withCustomData(custDatastring)
.withComputerName(linuxVMName)
.withExistingStorageAccount(storageAccount)
.withSize(vmSize())
.create();
How to pass a linux shell script here in the withCustomData part. I know the input for the method is Base64 encoded string. I am trying to pass an example script
#!/bin/bash
echo "This is some text" > randomtext.txt
p.s: I can't create a file for the script here, i have to pass the above command directly to the api. That is my requirement.
How should i handle the customdata part here. Any help is appreciated.
vm create request osprofile json
"osProfile":{"computerName":"xxxx","adminUsername":"xxx","adminPassword":"xxx","customData":"IyEvYmluL2Jhc2gKIGVjaG8gIlRoaXMgaXMgc29tZSB0ZXh0IiA+IHJhbmRvbXRleHQudHh0","linuxConfiguration":{"disablePasswordAuthentication":false}}
response os profile
"osProfile": {
"computerName": "xxxx",
"adminUsername": "xxxx",
"linuxConfiguration": {
"disablePasswordAuthentication": false,
"provisionVMAgent": true
},
"secrets": [],
"allowExtensionOperations": true,
"requireGuestProvisionSignal": true
}
The image i use here is a custom linux image built on centos 8