gpt4 book ai didi

json - 通过 CLI 进行 Azure ARM 模板部署失败,并出现 .ps1 脚本扩展错误

转载 作者:行者123 更新时间:2023-12-03 03:03:43 24 4
gpt4 key购买 nike

我一直通过 Visual Studio 使用自定义脚本扩展名 (.ps1) 部署我的 ARM 模板,效果很好,它实际上也是通过 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 门户在自定义脚本扩展中显示此错误:

[
{
"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."
}
]

我已经尝试过:

任何指导将不胜感激

最佳答案

最后,在其他评论的帮助下,我解决了这个问题。我使用更简单的 helloworld.ps1 脚本进行了测试,并且它有效,所以显然我的 powershell 脚本存在问题。在 Visual Studio 中创建它时,它将以下内容放置在顶部:

<# Custom Script for Windows #>

接下来是脚本的其余部分。一旦我删除它并重新上传到我的 StorageAccount/Container,并删除 commandToExecute 中的 ./,就可以了。

感谢您的反馈。

关于json - 通过 CLI 进行 Azure ARM 模板部署失败,并出现 .ps1 脚本扩展错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46422683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com