我一直致力于使用Microsoft CustomScriptExtension for VMs进行Azure VM部署的自动化。
http azure.microsoft.com/blog/2014/04/24/automating-vm-customization-tasks-using-custom-script-extension /
CustomScriptExtension在Azure门户中运行良好。我只需单击复选框以启用它,并指定位于Azure存储容器上的powershell脚本,它将在启动后在VM上运行。它成功,退出代码为0。
我需要帮助的是通过Azure Powershell从命令行调用CustomScriptExtension。我正在使用azure-xplat-cli从CLI创建Azure Windows VM,一切正常(从VM启动,包括云服务创建和角色创建,到端点创建,端点ACL创建,在VM上启用CustomScriptExtension)。当我尝试使用Azure Powershell运行CustomScriptExtension时,它会失败。
似乎CustomScriptExtension有效,脚本已下载,但失败并退出代码1。 但是,如果我在命令行上手动运行相同的脚本,则会成功。
如果没有更详细的错误消息,我似乎无法找到根本原因。
提前致谢, 杰夫
下面是一些比较成功运行与通过Azure Powershell运行失败的日志:
对于w95app11从Azure门户页面启动时(和CustomScriptExtension有效)。日志如下:
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
当我从Azure Powershell调用CustomScriptExtension时,相同的脚本失败,退出代码为1.日志如下: 注意:CustomScriptExtension运行正常,脚本已下载并运行,但出现代码为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