[CustomScript] extension blocks deployment when using bare command line
See original GitHub issueI’ve been trying to get this extension to do the simplest thing that could possibly work, which is to run a single command line upon provisioning:
"settings": {
"commandToExecute": "sudo apt-get -y update && sudo apt-get -y dist-upgrade"
}
But whenever I try to do this, my deployments never finish - the extension is created, its provisioning state is set to “running”, but I don’t get any debug output when looking at the properties blade for the extension on the machine it’s provisioned for.
Looking at the code, I believe it is blowing up at:
a) Line 192, where blob_uris is tested for lack of content, even though the documentation states that the fileUris
array is optional. This because Line 179 would seem to return None
in case the setting is missing.
b) Line 278 and following, given that the command line might be mangled by parse_args
- which goes against expectations for a Linux sysadmin.
In short, the extension should cover the case of running a bare command line (I would also vastly prefer to be able to inline a full script rather than having to manage access to a storage account, but I’ll file issue #216 for that).
For completion, here’s the relevant resource in the ARM template I’m using:
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"copy": {
"name": "rancher-master-provisioning-loop",
"count": "[parameters('masterCount')]"
},
"name": "[concat(parameters('virtualMachineNameMaster'), copyIndex(), '/updatePackages')]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"properties": {
"publisher": "Microsoft.OSTCExtensions",
"type": "CustomScriptForLinux",
"typeHandlerVersion": "1.5",
"autoUpgradeMinorVersion": true,
"settings": {
"commandToExecute": "sh sudo apt-get -y update && sudo apt-get -y dist-upgrade"
}
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineNameMaster'), copyIndex())]"
]
},
Issue Analytics
- State:
- Created 7 years ago
- Comments:15 (15 by maintainers)
Top GitHub Comments
Just to provide input here, @rcarmo is right, the current version of CustomScriptExtension uses
shlex.split
which splitswhoami && whoami
intoexec(['whoami', '&&', 'whoami'])
which is clearly invalid.In this case this is bug(and also by-design) and fileUris should be used for that.
Easiest workaround is to say
"commandToExecute": "sh -c 'whoami && whoami;'"
(I realized @rcarmo missed the-c
earlier, the failure listed a few comments above happened due to that).The new version of the Custom Script Extension (which we have not yet published) at https://github.com/Azure/custom-script-extension-linux always uses
sh -c
to run the specified comment (likeshell=True
in Python subprocess), so this issue will be fixed in theshortmedium term.@ahmetalpbalkan thanks for that. Saw that repo earlier (I also do Go), hope multi-line scripts as discussed in #216 make their way into the feature set.
Meanwhile, the good news is that I think we can close this as far as the deployment hangup is concerned:
I’ve tested my template with
typeHandlerVersion
set to1.0
as @boumenot did in his example, and the deployment worked (with a singlewhoami
command, I’m leaving the multi-command stuff to #216, which is where we should probably take thesilex.split
discussion).Which means there’s likely to be a bug in the resource provider (or the extension as currently deployed in production) where it regards checking that version number - with
1.5
, the deployment never finished, but there were also no error messages or command status sent back to the portal, as reported above.Thanks for all your help, I’ll keep hammering at the multi-line aspect in #216 because I think that will be a nice improvement for our customers.