问题描述
我正在尝试创建一个模板,该模板将通过使用复制功能来部署具有可变数量的多个数据磁盘的多个VM.我正在严格遵循文档,但是我的部署仍然失败. https://docs.microsoft.com/zh-cn/azure/azure-resource-manager/resource-group-create-multiple#create-multiple-instances-when-copy-wont-work 请帮我解决这个问题.azuredeploy.json:
{"$ schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion":"1.0.0.0",参数": {"adminUsername":{"type":"string",元数据":{"description":虚拟机的用户名."}},"adminPassword":{"type":安全字符串",元数据":{"description":虚拟机的密码".}},"dnsLabelPrefix":{"type":"string",元数据":{"description":用于访问虚拟机的公用IP的唯一DNS名称."}},"windowsOSVersion":{"type":"string","defaultValue":"2012-R2-Datacenter","allowedValues":["2008-R2-SP1","2012-数据中心","2012-R2-数据中心"],元数据":{"description":"VM的Windows版本.它将为该给定的Windows版本选择完全修补的映像.允许的值:2008-R2-SP1、2012-Datacenter,2012-R2-Datacenter."}},"numDataDisks":{"type":"int","maxValue":64,元数据":{"description":此参数允许用户选择所需的磁盘数"}},"numberOfInstances":{"type":"int","defaultValue":2元数据":{"description":要部署的VM数"}},"numberOfDataDisksPerVM":{"type":"array","defaultValue":[1,2]},"_artifactsLocation":{"type":字符串"},"_artifactsLocationSasToken":{"type":安全字符串"}},变量":{"storageAccountName":"[concat(uniquestring(resourceGroup().id),'dynamicdisk')]]","sizeOfDataDisksInGB":100,"diskCaching":"ReadWrite","imagePublisher":"MicrosoftWindowsServer","imageOffer":"WindowsServer","OSDiskName":"osdiskforwindowssimple","nicName":"dynamicDisksVMNic","addressPrefix":"10.0.0.0/16","subnetName":子网","subnetPrefix":"10.0.0.0/24","storageAccountType":"Standard_LRS","publicIPAddressName":"dynamicDisksPublicIP","publicIPAddressType":动态","vmStorageAccountContainerName":"vhds","vmName":"dynamicDisksVM","vmSize":"Standard_DS4","virtualNetworkName":"dynamicDisksVNET","vnetID":"[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]","subnetRef":"[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]","apiVersion":"2015-06-15","diskArray":[{"name":"datadisk1","lun":0,"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk1.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"},{"name":"datadisk2","lun":1"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk2.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"},{"name":"datadisk3","lun":2"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk3.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"},{"name":"datadisk4","lun":3,"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk4.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"},],"nested-TemplateFolder":"nestedtemplates","nested-TemplateFileName":"nested-.json","nested-TemplateParametersFileName":"nested-.parameters.json"},资源": [{"type":"Microsoft.Storage/storageAccounts","name":"[variables('storageAccountName')]","apiVersion":"[variables('apiVersion')]","location":"[resourceGroup().location]",特性": {"accountType":"[variables('storageAccountType')]"}},{"apiVersion":"[variables('apiVersion')]","type":"Microsoft.Network/publicIPAddresses","name":"[variables('publicIPAddressName')]","location":"[resourceGroup().location]",特性": {"publicIPAllocationMethod":"[variables('publicIPAddressType')]","dnsSettings":{"domainNameLabel":"[parameters('dnsLabelPrefix')]"}}},{"apiVersion":"[variables('apiVersion')]","type":"Microsoft.Network/virtualNetworks","name":"[variables('virtualNetworkName')]","location":"[resourceGroup().location]",特性": {"addressSpace":{"addressPrefixes":["[variables('addressPrefix')]"]},子网":[{"name":"[variables('subnetName')]",特性": {"addressPrefix":"[variables('subnetPrefix')]"}}]}},{"apiVersion":"[variables('apiVersion')]","type":"Microsoft.Network/networkInterfaces","name":"[variables('nicName')]","location":"[resourceGroup().location]",取决于": ["[concat('Microsoft.Network/publicIPAddresses/',变量('publicIPAddressName'))]","[concat('Microsoft.Network/virtualNetworks/',变量('virtualNetworkName'))]],特性": {"ipConfigurations":[{"name":"ipconfig1",特性": {"privateIPAllocationMethod":动态","publicIPAddress":{"id":"[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"},子网":{"id":"[variables('subnetRef')]"}}}]}},{"apiVersion":"[variables('apiVersion')]","type":"Microsoft.Compute/virtualMachines","name":"[concat('myvm',copyIndex())]",复制": {"name":"virtualMachineLoop","count":"[parameters('numberOfInstances')]"},"location":"[resourceGroup().location]",取决于": ["[concat('Microsoft.Storage/storageAccounts/',变量('storageAccountName'))]","[concat('Microsoft.Network/networkInterfaces/',variables('nicName'))]],特性": {"hardwareProfile":{"vmSize":"[变量('vmSize')]"},"osProfile":{"computerName":"[variables('vmName')]","adminUsername":"[parameters('adminUsername')]","adminPassword":"[parameters('adminPassword')]"},"storageProfile":{"imageReference":{"publisher":"[variables('imagePublisher')]","offer":"[variables('imageOffer')]","sku":"[parameters('windowsOSVersion')]",版本":最新"},"osDisk":{"name":"osdisk","vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]},"caching":"ReadWrite","createOption":"FromImage"},"dataDisks":"[引用(concat('nested-',copyIndex())).outputs.result.value]"},"networkProfile":{"networkInterfaces":[{"id":"[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"}]},"diagnosticsProfile":{"bootDiagnostics":{"enabled":"true","storageUri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]"}}}},{"name":"[concat('nested-',copyIndex())]","type":"Microsoft.Resources/deployments","apiVersion":"2016-09-01",取决于": [],复制": {"name":"deploycopy","count":"[parameters('numberOfInstances')]"},特性": {"mode":增量","templateLink":{"uri":"[concat(parameters('_ artifactsLocation'),'/',变量('nested-TemplateFolder'),'/',变量('nested-TemplateFileName'),参数('_artifactsLocationSasToken'))]"","contentVersion":"1.0.0.0"},"parametersLink":{"uri":"[concat(parameters('_ artifactsLocation'),'/',变量('nested-TemplateFolder'),'/',变量('nested-TemplateParametersFileName'),parameters('_ artifactsLocationSasToken'))]]","contentVersion":"1.0.0.0"},参数": {"vmName":{"value":"[concat('myvm',copyIndex())]"},"storageAccountName":{"value":"[variables('storageAccountName')]"},"numDataDisks":{"value":"[parameters('numberOfDataDisksPerVM')[copyIndex()]]"}}}}]}
nested-.json
{"$ schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion":"1.0.0.0",参数": {"vmName":{"type":字符串"},"storageAccountName":{"type":字符串"},"numDataDisks":{"type":"int","maxValue":16元数据":{"description":此参数允许用户选择所需的磁盘数"}}},变量":{"diskArray":[{"name":"datadisk1","lun":0,"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk1.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"},{"name":"datadisk2","lun":1"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk2.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"},{"name":"datadisk3","lun":2"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk3.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"},{"name":"datadisk4","lun":3,"vhd":{"uri":"[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk4.vhd')]"},"createOption":空","caching":"[variables('diskCaching')]","diskSizeGB":"[variables('sizeOfDataDisksInGB')]"}]},资源": [],输出":{结果": {"type":"array","value":"[take(variables('diskArray'),parameters('numDataDisks'))]"}}}
这整个事情现在没有意义了.您应该立即使用属性副本:
https://github.com/rjmax/Build2017/blob/master/Act1.TemplateEnhancements/Chapter02.PropertyCopies.json
I'm trying to create a template that will deploy Multiple VMs with variable ammount of multiple data disks by using copy function. I'm following documentation precisely, but my deployment still fails.https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#create-multiple-instances-when-copy-wont-workPlease, help me fix this.azuredeploy.json:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"dnsLabelPrefix": {
"type": "string",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"windowsOSVersion": {
"type": "string",
"defaultValue": "2012-R2-Datacenter",
"allowedValues": [
"2008-R2-SP1",
"2012-Datacenter",
"2012-R2-Datacenter"
],
"metadata": {
"description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter."
}
},
"numDataDisks": {
"type": "int",
"maxValue": 64,
"metadata": {
"description": "This parameter allows the user to select the number of disks they want"
}
},
"numberOfInstances": {
"type": "int",
"defaultValue": 2,
"metadata": {
"description": "Number of VMs to deploy"
}
},
"numberOfDataDisksPerVM": {
"type": "array",
"defaultValue": [ 1, 2 ]
},
"_artifactsLocation": {
"type": "string"
},
"_artifactsLocationSasToken": {
"type": "securestring"
}
},
"variables": {
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'dynamicdisk')]",
"sizeOfDataDisksInGB": 100,
"diskCaching": "ReadWrite",
"imagePublisher": "MicrosoftWindowsServer",
"imageOffer": "WindowsServer",
"OSDiskName": "osdiskforwindowssimple",
"nicName": "dynamicDisksVMNic",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"storageAccountType": "Standard_LRS",
"publicIPAddressName": "dynamicDisksPublicIP",
"publicIPAddressType": "Dynamic",
"vmStorageAccountContainerName": "vhds",
"vmName": "dynamicDisksVM",
"vmSize": "Standard_DS4",
"virtualNetworkName": "dynamicDisksVNET",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"apiVersion": "2015-06-15",
"diskArray": [
{
"name": "datadisk1",
"lun": 0,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk1.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
},
{
"name": "datadisk2",
"lun": 1,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk2.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
},
{
"name": "datadisk3",
"lun": 2,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk3.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
},
{
"name": "datadisk4",
"lun": 3,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk4.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
},
],
"nested-TemplateFolder": "nestedtemplates",
"nested-TemplateFileName": "nested-.json",
"nested-TemplateParametersFileName": "nested-.parameters.json"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[resourceGroup().location]",
"properties": {
"accountType": "[variables('storageAccountType')]"
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[concat('myvm', copyIndex())]",
"copy": {
"name": "virtualMachineLoop",
"count": "[parameters('numberOfInstances')]"
},
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
},
"dataDisks": "[reference(concat('nested-', copyIndex())).outputs.result.value]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": "true",
"storageUri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]"
}
}
}
},
{
"name": "[concat('nested-', copyIndex())]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"copy": {
"name": "deploycopy",
"count": "[parameters('numberOfInstances')]"
},
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('nested-TemplateFolder'), '/', variables('nested-TemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parametersLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('nested-TemplateFolder'), '/', variables('nested-TemplateParametersFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"vmName": { "value": "[concat('myvm', copyIndex())]" },
"storageAccountName": { "value": "[variables('storageAccountName')]" },
"numDataDisks": { "value": "[parameters('numberOfDataDisksPerVM')[copyIndex()]]" }
}
}
}
]
}
nested-.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"storageAccountName": {
"type": "string"
},
"numDataDisks": {
"type": "int",
"maxValue": 16,
"metadata": {
"description": "This parameter allows the user to select the number of disks they want"
}
}
},
"variables": {
"diskArray": [
{
"name": "datadisk1",
"lun": 0,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk1.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
},
{
"name": "datadisk2",
"lun": 1,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk2.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
},
{
"name": "datadisk3",
"lun": 2,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk3.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
},
{
"name": "datadisk4",
"lun": 3,
"vhd": {
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk4.vhd')]"
},
"createOption": "Empty",
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGB')]"
}
]
},
"resources": [
],
"outputs": {
"result": {
"type": "array",
"value": "[take(variables('diskArray'),parameters('numDataDisks'))]"
}
}
}
this whole thing doesn't make sense now. You should use the properties copy now:
https://github.com/rjmax/Build2017/blob/master/Act1.TemplateEnhancements/Chapter02.PropertyCopies.json
这篇关于Azure RM模板.具有多个数据磁盘的多个VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!