2017-09-26 66 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 –

相關問題