2017-03-02 88 views
4

使用以下json模板創建虛擬機時,我已將多個數據磁盤添加到虛擬機。在創建一個虛擬機,但是在建立多個虛擬機,機器未能創造如何爲天青虛擬機創建數據磁盤?

"variables": { 
"diskArray": [ 
{ 
"name": "datadisk1", 
"lun": 0, 
"vhd": { 
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk1.vhd')]" 
     }, 
     "createOption": "Empty",  
     "caching": "ReadWrite",  
     "diskSizeGB": 300  
     },  
     {  
     "name": "datadisk2", 
     "lun": 1, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk2.vhd')]"  
     }, 
     "createOption": "Empty",  
     "caching": "ReadWrite",  
     "diskSizeGB": 200 
     }, 
     { 
     "name": "datadisk3", 
     "lun": 2, 
     "vhd": { 
      "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk3.vhd')]" 
     }, 
     "createOption": "Empty", 
     "caching": "ReadWrite", 
     "diskSizeGB": 100 
     } 
]  
    },  
.....  
..... 
"resources": [ 
    { 
     "apiVersion": "2015-06-15", 
     "type": "Microsoft.Compute/virtualMachines", 
     "name": "[concat(parameters('VmPrefix'), copyindex(1))]", 
     "copy": { 
     "name": "Datanode", 
     "count": "[variables('vmcount')]" 
     }, 
     "location": "[resourceGroup().location]", 
     "properties": { 
     ...... 
     ...... 
     "storageProfile": { 
      "imageReference": { 
      ........ 
      }, 
      "dataDisks": "[take(variables('diskArray'),parameters('numDataDisks'))]", 
      "osDisk": { 
      ....... 
      } 
     } 
    } 
} 
] 

此代碼工作正常。這是因爲第一臺機器的datadisk創建的vhd與其他機器相同。

有沒有辦法用不同的名字創建一個vhd? 嘗試傳遞複製索引,但不起作用。

回答

2

當然,我會粘貼一個鏈接到一個模板,並解釋它是如何工作的。這裏是link

所以爲了做到這一點,你必須添加copyindex(或類似的東西)到磁盤的名字,做的方法之一,是使用嵌套的模板,將它與磁盤返回一個對象,並在調用模板時可以使用copyindex作爲參數。

This is其中創建嵌套部署以創建磁盤對象。
here您使用輸出來創建磁盤。

+0

運行上面的示例json時,我得到了以下錯誤:New-AzureRmResourceGroupDeployment:對象引用未設置爲對象的實例。 在線:1 char:13 + $ response = New-AzureRmResourceGroupDeployment -ResourceGroupName $ ResourceGroup ... + ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ + CategoryInfo:CloseError:(:) [New-AzureRmResourceGroupDeployment],NullReferenceException + FullyQualifiedErrorId:Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand –

+0

但虛擬機使用數據磁盤正確創建。 –

+1

好吧,我不確定你在做什麼錯誤,對我來說這工作正常,如果這樣做你所要求的,接受這個答案;)我剛剛測試過這個部署,它工作正常。 '新AzureRmResourceGroupDeployment -Name測試-ResourceGroupName zxc -TemplateUri https:// raw.githubusercontent.com/4c74356b41/armotron/master/ml-vm-ml-dd.json' – 4c74356b41