1

I’ve been working on automation for Azure VM deployment with the Microsoft CustomScriptExtension for VMs.

http azure.microsoft.com/blog/2014/04/24/automating-vm-customization-tasks-using-custom-script-extension/

The CustomScriptExtension works great from the Azure portal. I just click on the checkbox to enable it, and specify the powershell script located on the Azure storage container and it will run on the VM after it boots up. It succeeds with exit code of 0.

What I need help on is calling the CustomScriptExtension from command line via the Azure Powershell. I’m using azure-xplat-cli to create an Azure Windows VM from the CLI, and everything works (from VM launch encompassing cloud service creation and role creation, to endpoint creation, endpoint ACL creation, enabling CustomScriptExtension on the VM). When I then try to use Azure Powershell to run CustomScriptExtension it fails.

I followed the directions here: http://fabriccontroller.net/blog/posts/customizing-your-microsoft-azure-virtual-machines-with-the-new-customscript-extension/

It appears CustomScriptExtension works, the script is downloaded, but it fails with exit code 1. However, if I run the same script manually on the command line, it succeeds.

I can’t seem to get to the root cause without more verbose error messages.

Thanks in advance, Jeff

Below are some logs comparing a successful run vs the unsuccessful run via Azure Powershell:

For w99app11 when it was launched from Azure portal page (and CustomScriptExtension works). Logs follow:

PS C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension\1.1>
cat .\CustomScriptHandler.log
2015-01-14T20:15:48.4897999Z    [Info]: Starting IaaS ScriptHandler Extension v1
2015-01-14T20:15:48.5054217Z    [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomS
criptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Microso
ft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T20:15:48.5054217Z    [Info]: Installing Handler
2015-01-14T20:15:48.5054217Z    [Info]: Handler successfully installed
2015-01-14T20:15:51.6818933Z    [Info]: Starting IaaS ScriptHandler Extension
v1
2015-01-14T20:15:51.6818933Z    [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomS
criptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Microso
ft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T20:15:51.6818933Z    [Info]: Enabling Handler
2015-01-14T20:15:51.6818933Z    [Info]: Handler successfully enabled
2015-01-14T20:15:51.7287562Z    [Info]: Loading configuration for sequence number 0
2015-01-14T20:15:51.8284233Z    [Info]: HandlerSettings = ProtectedSettingsCertThumbprint: , ProtectedSettings: {}, Public Settings: {FileUris: [https://portalv
hdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1?sv=2014-02-14&sr=b&sig=qOObvkYmT1pZS7tdFbMYPBeGryD76fz7tfsl8kiSCV0%3D&st=2015-01-14T20%3A03
%3A54Z&se=2114-12-21T20%3A05%3A54Z&sp=r], CommandToExecute: powershell.exe -ExecutionPolicy Unrestricted -File bootstrap-ansible.ps1 }
2015-01-14T20:15:51.8440422Z    [Info]: Downloading files specified in configuration...
2015-01-14T20:15:51.8909155Z    [Info]: DownloadFiles: fileUri = "https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1?sv=2014-02
-14&sr=b&sig=qOObvkYmT1pZS7tdFbMYPBeGryD76fz7tfsl8kiSCV0=&st=2015-01-14T20:03:54Z&se=2114-12-21T20:05:54Z&sp=r", baseUri = "https://portalvhdslqdvg9p4yz1f8.blob
.core.windows.net/"
2015-01-14T20:15:52.2971695Z    [Info]: Files downloaded. Asynchronously executing command: 'powershell.exe -ExecutionPolicy Unrestricted -File bootstrap-ansibl
e.ps1 '
2015-01-14T20:15:52.3127877Z    [Info]: Command execution task started.  Awaiting completion...
2015-01-14T20:16:16.6145937Z    [Info]: Command execution finished. Command exited with code: 0

When I call CustomScriptExtension from Azure Powershell, the same script fails with exit code 1. Logs follow: NOTE: the CustomScriptExtension run worked, and the script was downloaded and run, but failed on an error with exit code 1

cd C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\
cat .\CustomScriptHandler.log



2015-01-14T19:16:24.4301817Z    [Info]: Starting IaaS ScriptHandler Extension v1
2015-01-14T19:16:24.4301817Z    [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\ Logs\Plugins\Microsoft.Compute.Custom
ScriptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Micros
oft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T19:16:24.4458090Z    [Info]: Enabling Handler
2015-01-14T19:16:24.4458090Z    [Info]: Handler successfully enabled
2015-01-14T19:16:24.4458090Z    [Info]: Loading configuration for sequence number 2
2015-01-14T19:16:24.4770569Z    [Info]: HandlerSettings = ProtectedSettingsCertThumbprint: , ProtectedSettings: {}, Public Settings: {FileUris: [https://portalv
hdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1], CommandToExecute: powershell -ExecutionPolicy Unrestricted -file ./bootstrap-ansible.ps1
}
2015-01-14T19:16:24.4770569Z    [Info]: Downloading files specified in configuration...
2015-01-14T19:16:24.5083104Z    [Info]: DownloadFiles: fileUri = "https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1", baseUri
="https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/"
2015-01-14T19:16:24.8823100Z    [Info]: Files downloaded. Asynchronously executing command: 'powershell -ExecutionPolicy Unrestricted -file ./bootstrap-ansible.
ps1 '
2015-01-14T19:16:24.8979517Z    [Info]: Command execution task started.  Awaiting completion...
2015-01-14T19:16:29.7456296Z    [Error]:        Command execution finished.  Command exited with code: 1
  • 1
    I found an explanation. It was due to permissions. I'm new to all of this and did not realize that CustomScriptExtension does not run with local admin priviledges. http://azure.microsoft.com/blog/2014/07/15/automating-sql-server-vm-configuration-using-custom-script-extension/ – Jeffrey Liu Jan 18 '15 at 15:42

0 Answers0