首页 文章

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

提问于
浏览
1

我一直在使用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门户在自定义脚本扩展中显示此错误:

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

我试过了:

任何指导将不胜感激

3 回答

  • 0

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

    <# Custom Script for Windows #>
    

    其次是脚本 . 一旦我将其删除并重新上传到我的StorageAccount / Container,并在commandToExecute中删除./,就可以了 .

    感谢您的反馈 .

  • 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"
        }
    }
    
  • 1

    当我在实验室中测试您的模板时,我会得到相同的错误日志 . 当我删除 ./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 .

相关问题