2017-09-26 60 views
1

我一直在使用自定义脚本扩展(.ps1)通过Visual Studio部署我的ARM模板,它实际上也是通过VS编译的。但是,我一直试图通过CLI对Azure存储位置上的.ps1文件进行修改来部署它,以便可以由没有VS的其他人部署。但是,每次执行部署时都会失败,该脚本没有.ps1扩展名的错误。通过CLI的Azure ARM模板部署失败.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." 
    } 
] 

我曾尝试:

任何指导意见将非常感激

回答

1

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

<# Custom Script for Windows #> 

其后是脚本的其余部分。一旦我删除并重新上传到我的StorageAccount /容器,并删除./在commandToExecute,它没事。

感谢您的反馈意见。

+0

我在我的实验室测试,我认为根本原因是你应该删除''''命令。 'powershell.exe -ExecutionPolicy Unrestricted -NoProfile -onInteractive -File。/ customscript/formatDatadisk1.ps1' –

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" 
    } 
} 
+0

不幸的是,这并没有什么区别,但它仍然失败,并出现相同的错误。 – Beefcake

+0

检查更新回答 – 4c74356b41

+0

我还在这里挣扎。我设置了类似你的代码,但仍然失败,刚才我设置autoUpgradeMinorVersion为false,希望版本可能不喜欢它,但它又失败了。 – Beefcake

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

+0

@Beefcake如果我使用'“commandToExecute”:“powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File'./formatDatadisk1.ps1'”'你可以尝试删除'./ '。我相信它会起作用。 –

+0

我以前没有使用过./,并没有奏效。不幸的是,今天我还没有另一次机会部署脚本,但明天早上我会再试一次。 – Beefcake

+0

@Beefcake很好,你也可以检查登录虚拟机。 https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript#troubleshoot-and-support –

相关问题