Azure

使用 json 模板部署新機器時儲存配置文件錯誤

  • November 14, 2017

我正在嘗試使用 Visual Studio 2015 在 avset 中部署兩個虛擬機。

我嘗試部署時收到以下錯誤消息:

New-AzureRmResourceGroupDeployment : 2:03:59 AM - Resource Microsoft.Compute/virtualMachines '31' failed with message '{
 "error": {
   "details": [
     {
       "target": "vm.properties.storageProfile.networkProfile",
       "message": "Could not find member 'networkProfile' on object of type 'StorageProfile'. Path 'properties.storageProfile.networkProfile', line 1, position 893."
     },
     {
       "target": "vm.properties.outputs",
       "message": "Could not find member 'outputs' on object of type 'Properties'. Path 'properties.outputs', line 1, position 1072."
     }
   ],
   "code": "BadRequest",
   "message": "The request message is invalid."
 }
}'
At C:\Users\Base\Desktop\Azure-Deploy.ps1:5 char:1
+ New-AzureRmResourceGroupDeployment -Name DCDeploy -ResourceGroupName  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
   + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

New-AzureRmResourceGroupDeployment : 2:03:59 AM - Could not find member 'networkProfile' on object of type 'StorageProfile'. Path 'properties.storageProfile.networkProfile', line 1, position 893.
At C:\Users\Base\Desktop\Azure-Deploy.ps1:5 char:1
+ New-AzureRmResourceGroupDeployment -Name DCDeploy -ResourceGroupName  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
   + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

New-AzureRmResourceGroupDeployment : 2:03:59 AM - Could not find member 'outputs' on object of type 'Properties'. Path 'properties.outputs', line 1, position 1072.
At C:\Users\Base\Desktop\Azure-Deploy.ps1:5 char:1
+ New-AzureRmResourceGroupDeployment -Name DCDeploy -ResourceGroupName  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
   + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

我的模板如下:

{
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
   "stdAdminUserName": {
     "type": "string",
     "minLength": 1
   },
   "stdAdminPassword": {
     "type": "securestring"
   },
   "storageAccountName": {
     "type": "string",
     "minLength": 1
   },
   "storageAccountType": {
     "type": "string",
     "allowedValues": [
       "Standard_LRS",
       "Standard_GRS"
     ]
   },
   "faultDomains": {
     "type": "int"
   },
   "updateDomains": {
     "type": "int"
   },
   "applicationid": {
     "type": "string",
     "minLength": 1
   },
   "sharedservice": {
     "type": "string",
     "minLength": 1
   },
   "msdref": {
     "type": "string",
     "minLength": 1
   },
   "project": {
     "type": "string",
     "minLength": 1
   },
   "costcentre": {
     "type": "string",
     "minLength": 1
   },
   "templateref": {
     "type": "string",
     "minLength": 1
   },
   "environment": {
     "type": "string",
     "minLength": 1
   },
   "operatingsystem": {
     "type": "string",
     "minLength": 1
   },
   "deploymentzone": {
     "type": "string",
     "minLength": 1
   },
   "shutdownschedule": {
     "type": "string",
     "minLength": 1
   },
   "avSetName": {
     "type": "string",
     "minLength": 1
   },
   "vmInstances": {
     "type": "int"
   },
   "vmSize": {
     "type": "string",
     "minLength": 1
   },
   "vmDiskSize": {
     "type": "string",
     "minLength": 1
   },
   "networkName": {
     "type": "string",
     "minLength": 1
   },
   "networkResourceGroup": {
     "type": "string",
     "minLength": 1
   },
   "subnetName": {
     "type": "string",
     "minLength": 1
   },
   "vmNicNamePrefix": {
     "type": "string",
     "minLength": 1
   },
   "vmNamePrefix": {
     "type": "string",
     "minLength": 1
   }
 },
 "variables": {
   "VNetID": "[resourceId(Parameters('networkResourceGroup'), 'Microsoft.Network/virtualNetworks', Parameters('networkname'))]",
   "SubnetRef": "[resourceid(variables('VNetID'), '/subnets/', Parameters('subnetName'))]",
   "stdVMImagePublisher": "MicrosoftWindowsServer",
   "stdVMImageOffer": "WindowsServer",
   "stdWindowsOSVersion": "2012-R2-Datacenter",
   "stdVHDContainerName": "vhds",
   "VMOSDiskNamePrefix": "VMOSDisk",
   "VMDATADisk1NamePrefix": "DataDisk1VM",
   "VMDATADisk2NamePrefix": "DataDisk2VM"
 },
 "resources": [
   {
     "name": "[Parameters('storageAccountName')]",
     "type": "Microsoft.Storage/storageAccounts",
     "location": "[resourceGroup().location]",
     "apiVersion": "2015-06-15",
     "dependsOn": [],
     "tags": {
       "displayname": "[Parameters('storageAccountName')]",
       "applicationid": "[Parameters('applicationid')]",
       "sharedservice": "[Parameters('sharedservice')]",
       "msdref": "[Parameters('msdref')]",
       "project": "[Parameters('project')]",
       "costcentre": "[Parameters('costcentre')]",
       "operatingsystem": "[Parameters('operatingsystem')]",
       "deploymentzone": "[Parameters('deploymentzone')]",
       "shutdownschedule": "[Parameters('shutdownschedule')]"
     },
     "properties": {
       "accountType": "[Parameters('storageAccountType')]"
     }
   },
   {
     "name": "[parameters('avSetName')]",
     "type": "Microsoft.Compute/availabilitySets",
     "location": "[resourceGroup().location]",
     "apiVersion": "2015-06-15",
     "dependsOn": [],
     "tags": {
       "displayName": "[parameters('avSetName')]"
     },
     "properties": {
       "platformUpdateDomainCount": "[parameters('updateDomains')]",
       "platformFaultDomainCount": "[parameters('faultDomains')]"
     }
   },
   {
     "name": "[concat(Parameters('vmNicNamePrefix'), copyindex(1))]",
     "type": "Microsoft.Network/networkInterfaces",
     "location": "[resourceGroup().location]",
     "apiVersion": "2015-06-15",
     "copy": {
       "name": "nicLoop",
       "count": "[parameters('vmInstances')]"
     },
     "tags": {
       "costcenter": "[Parameters('costcentre')]",
       "environment": "[Parameters('environment')]",
       "project": "[Parameters('project')]",
       "role": "vmnic",
       "templateref": "[Parameters('templateRef')]"
     },
     "properties": {
       "ipConfigurations": [
         {
           "name": "ipconfig1",
           "properties": {
             "privateIPAllocationMethod": "Dynamic",
             "subnet": {
                "id": "[variables('SubnetRef')]"
             }
           }
         }
       ]
     }
   },
   {
     "name": "[concat(parameters('vmInstances'), copyindex(1))]",
     "type": "Microsoft.Compute/virtualMachines",
     "location": "[resourceGroup().location]",
     "apiVersion": "2015-06-15",
     "dependsOn": [
       "[concat('Microsoft.Storage/storageAccounts/', Parameters('storageAccountName'))]",
       "[concat('Microsoft.Compute/availabilitySets/', Parameters('avSetName'))]",
       "nicLoop"
     ],
     "copy": {
       "name": "virtualMachineLoop",
       "count": "[parameters('vmInstances')]"
     },
     "tags": {
       "applicationid": "[Parameters('applicationid')]",
       "costcentre": "[Parameters('costcentre')]",
       "deploymentzone": "[Parameters('deploymentzone')]",
       "displayname": "[concat(parameters('vmInstances'), copyindex(1))]",
       "environment": "[Parameters('environment')]",
       "msdref": "[Parameters('msdref')]",
       "operatingsystem": "[Parameters('operatingsystem')]",
       "project": "[Parameters('project')]",
       "sharedservice": "[Parameters('sharedservice')]"
     },
     "properties": {
       "availabilitySet": {
         "id": "[resourceId('Microsoft.Compute/availabilitySets',parameters('avSetName'))]"
       },
       "hardwareProfile": {
         "vmSize": "[Parameters('vmSize')]"
       },
       "osProfile": {
         "computerName": "[concat(parameters('vmInstances'), copyindex(1))]",
         "adminUsername": "[Parameters('stdAdminUserName')]",
         "adminPassword": "[Parameters('stdAdminPassword')]"
       },
       "storageProfile": {
         "imageReference": {
           "publisher": "[variables('STDVMImagePublisher')]",
           "offer": "[variables('STDVMImageOffer')]",
           "sku": "[variables('stdWindowsOSVersion')]",
           "version": "latest"
         },
         "osDisk": {
           "name": "[concat(variables('VMOSDiskNamePrefix'), copyindex(1))]",
           "vhd": {
             "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('VMOSDiskNamePrefix'), copyindex(1), '.vhd')]"
           },
           "caching": "ReadWrite",
           "createOption": "FromImage"
         },
         "networkProfile": {
           "networkInterfaces": [
             {
               "id": "[resourceId('Microsoft.Network/networkInterfaces', concat(Parameters('vmNicNamePrefix'), copyindex(1)))]"
             }
           ]
         }

       },
       "outputs": {
       }
     }
   }
 ]
}

您可以使用 NotePad++ 檢查,網路配置文件在您的 storageProfile 中。但它們是並列的屬性。錯誤日誌也告訴你這一點。

在此處輸入圖像描述

您可以嘗試以下模板。

   "properties": {
       "availabilitySet": {
           "id": "[resourceId('Microsoft.Compute/availabilitySets',parameters('avSetName'))]"
       },
       "hardwareProfile": {
           "vmSize": "[Parameters('vmSize')]"
       },
       "osProfile": {
           "computerName": "[concat(parameters('vmInstances'), copyindex(1))]",
           "adminUsername": "[Parameters('stdAdminUserName')]",
           "adminPassword": "[Parameters('stdAdminPassword')]"
       },
       "storageProfile": {
           "imageReference": {
               "publisher": "[variables('STDVMImagePublisher')]",
               "offer": "[variables('STDVMImageOffer')]",
               "sku": "[variables('stdWindowsOSVersion')]",
               "version": "latest"
           },
           "osDisk": {
               "name": "[concat(variables('VMOSDiskNamePrefix'), copyindex(1))]",
               "vhd": {
                   "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('VMOSDiskNamePrefix'), copyindex(1), '.vhd')]"
               },
               "caching": "ReadWrite",
               "createOption": "FromImage"
           }
       },
       "networkProfile": {
           "networkInterfaces": [{
               "id": "[resourceId('Microsoft.Network/networkInterfaces', concat(Parameters('vmNicNamePrefix'), copyindex(1)))]"
           }]
       }

   }

注:是與和outputs平行的屬性。resources``variables

引用自:https://serverfault.com/questions/883300