我一直在通过Visual Studio部署我的ARM模板,并使用自定义脚本扩展名(.ps1),它实际上也是通过VS编译的。但是,我一直在尝试通过CLI对其进行部署,并对Azure存储位置上的.ps1文件进行了修改,以便其他没有VS的人可以部署它。但是,每次我进行部署时都会失败,脚本没有.ps1扩展名的错误。
我的ARM模板的自定义脚本扩展部分:
"name": "formatDataDisk",
"type": "extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2016-03-30",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
],
"tags": {
"displayName": "formatDataDisk"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.4",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://--MYSTORAGEACCOUNTNAME--.blob.core.windows.net/customscript/formatDataDisk.ps1"
],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File './customscript/formatDatadisk1.ps1'"
},
"protectedSettings": {
"storageAccountName": "--MYSTORAGEACCOUNTNAME--",
"storageAccountKey": "--MYSTORAGEKEY--"
}
在CLI部署结束时,它失败并显示:
msrest.http_logger : b'{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"Conflict","message":"{\\r\\n \\"status\\": \\"Failed\\",\\r\\n \\"error\\": {\\r\\n \\"code\\": \\"ResourceDeploymentFailure\\",\\r\\n \\"message\\": \\"The resource operation completed with terminal provisioning state \'Failed\'.\\",\\r\\n \\"details\\": [\\r\\n {\\r\\n \\"code\\": \\"VMExtensionProvisioningError\\",\\r\\n \\"message\\": \\"VM has reported a failure when processing extension \'formatDataDisk\'. Error message: \\\\\\"Finished executing command\\\\\\".\\"\\r\\n }\\r\\n ]\\r\\n }\\r\\n}"}]}}'
msrest.exceptions : At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
Deployment failed. {
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'formatDataDisk'. Error message: \"Finished executing command\"."
}
Azure Portal在自定义脚本扩展中显示此错误:
[
{
"code": "ComponentStatus/StdOut/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": ""
},
{
"code": "ComponentStatus/StdErr/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": "Processing -File ''./customscript/formatDatadisk1.ps1'' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again."
}
]
我试过了:
非常感谢任何指导
答案 0 :(得分:1)
最后,我已经在其他评论的帮助下解决了这个问题。我使用更简单的helloworld.ps1脚本进行了测试,并且它有效,所以很明显我的powershell脚本存在问题。在Visual Studio中创建它时,它将以下内容放在顶部:
<# Custom Script for Windows #>
其次是脚本。一旦我将其删除并重新上传到我的StorageAccount / Container,并在commandToExecute中删除./,就可以了。
感谢您的反馈。
答案 1 :(得分:0)
错误的路径,您需要在路径中省略容器:
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File './formatDatadisk1.ps1'"
它始终将下载的文件放在同一目录中,没有嵌套文件夹
这是适用于我的确切代码段:
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://backupcicd.blob.core.windows.net/deployment/iis-preConfigureScript.ps1"
],
"commandToExecute": "powershell -ExecutionPolicy Unrestricted -File iis-preConfigureScript.ps1"
}
}
答案 2 :(得分:0)
当我在实验室中测试您的模板时,我会得到相同的错误日志。当我删除./customscript/
时,它适用于我。
"resources": [
{
"name": "[concat(parameters('virtualMachineName'), '/', 'shuitest')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"location": "eastus",
"apiVersion": "2016-03-30",
"dependsOn": [ ],
"tags": {
"displayName": "shuitest"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.4",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["https://shuiwindisks928.blob.core.windows.net/vhds/open_port.ps1"]
},
"protectedSettings": {
"commandToExecute": "powershell -ExecutionPolicy Unrestricted -File open_port.ps1",
"storageAccountName" : "shuiwindisks928",
"storageAccountKey" : "jvYg+1aCo+d4b+FI/kdBOtE*******************+kXa0yZR5xrt7a57qgHw=="
}
}
}],
更新
您需要在VM上检查扩展日志,请参阅此link。
答案 3 :(得分:0)
我不确定是否与该特定问题相关,但是我最近3-4天在Azure自定义扩展上工作时注意到的是,如果脚本一次失败并且自定义扩展的ARM模板部署失败,那么您将必须从您要在其上运行脚本的Azure门户的扩展刀片下的VM中手动删除自定义扩展。如果您不执行此操作,则无论您对脚本进行了什么更改,自定义扩展名都将继续运行旧脚本。