1
votes

I want to run a script using Azure CLI command.

I am using following command to do it.

Command to execute:-

az vm extension set --resource-group rg1 --vm-name test --name CustomScript --publisher Microsoft.Azure.Extensions --version 2.0 --protected-settings '{"fileUris": ["https://test.blob.core.windows.net/testcontainer/test.sh?st=2018-05-28T19%3A56%3A00Z&se=2018-05-30T19%3A56%3A00Z&sp=r&sv=2017-04-17&sr=b&sig=LsAmSVWmggcBYXs7XwUhdA16HfSChi6%2FvH0vqjZMS%2F1YM%3D"], "commandToExecute": "bash test.sh 1 2 3"}'

I want to use like below to pass as variables in the command and am getting the following error

SCRIPT_LOCATION="https://test.blob.core.windows.net/testcontainer/test.sh?st=2018-05-28T19%3A56%3A00Z&se=2018-05-30T19%3A56%3A00Z&sp=r&sv=2017-04-17&sr=b&sig=LsAmSVWmggcBYXs7XwUhdA16HfSChi6%2FvH0vqjZMS%2F1YM%3D" SCRIPT_NAME="test.sh" PARAM1="test1" PARAM2="test2" PARAM3="test3"

Command to execute:-

az vm extension set --resource-group rg1 --vm-name test --name CustomScript --publisher Microsoft.Azure.Extensions --version 2.0 --protected-settings '{"fileUris": [$SCRIPT_LOCATION], "commandToExecute": "bash $SCRIPT_NAME $PARAM1 $PARAM2 $PARAM3"}'

Error:-

Deployment failed. Correlation ID: 72859669-9cdf-4bb0-9aac-1a6af52c7e1c. VM has reported a failure when processing extension 'CustomScript'. Error message: "Enable failed: failed to get configuration: json validation error: invalid protected settings JSON: fileUris.0: Does not match format 'uri'".

2
This looks like an issue with the extension rather than the CLI. If you try this with an ARM template or in Powershell do you get the same error? - Zahid Faroq
For your problem, I think you store the custom script in container of Azure Storage Account Blob. With the error, the file URI could be the wrong point. I did the test with the cli command, and the URI should be like this: teststore.blob.core.windows.net/vhds1/test.sh. So, i suggest you check the URI carefully. - Charles Xu
@Charles-MSFT I have solved the issue. Refer my answer. - Galet
@ZahidFaroq I have solved the issue. Refer my answer - Galet

2 Answers

2
votes

I am able to solve the above issue by using the following command. Following command works well.

az vm extension set --resource-group rg1 --vm-name test --name CustomScript --publisher Microsoft.Azure.Extensions --version 2.0 --protected-settings "{\"fileUris\": [\"$SCRIPT_LOCATION\"], \"commandToExecute\": \"bash $SCRIPT_NAME $PARAM1 $PARAM2 $PARAM3\"}"
0
votes

Here is a different way, that I like because it avoids the need to escape the double quotes (so JSON payload is more readable):

az vm extension set --name DSC --publisher Microsoft.Powershell --version 2.9 --vm-name DC -g $resourceGroupName \
    --settings '{"ModulesURL": "'${artifactsURI}'dsc/ConfigureDCVM.zip", "configurationFunction": "ConfigureDCVM.ps1\\ConfigureDCVM", "Properties": {"domainFQDN": "'${domainFQDN}'", "PrivateIP": "10.0.1.4"} }' \
    --protected-settings '{"Properties": {"AdminCreds": {"UserName": "'${adminUserName}'", "Password": "'${adminPassword}'" }, "AdfsSvcCreds": {"UserName": "'${adfsSvcUserName}'", "Password": "'${serviceAccountsPassword}'" }}}'