1

Ich kann eine Azure-VM mit einer bestimmten VHD aus der folgenden Vorlage erstellen, aber wie füge ich sie auch einem Verfügbarkeitsset hinzu. Ich kann das nach der VM-Erstellung nicht machen, also muss ich es hier machen.Hinzufügen der Verfügbarkeit Festlegen der Azure Virtual Machine-Vorlagenerstellung

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
     "location": { 
      "type": "string", 
      "metadata": { 
       "description": "Location to create the VM in" 
      } 
     }, 
     "osDiskVhdUri": { 
      "type": "string", 
      "metadata": { 
       "description": "Uri of the existing VHD" 
      } 
     }, 
     "osType": { 
      "type": "string", 
      "allowedValues": [ 
       "Windows", 
       "Linux" 
      ], 
      "metadata": { 
       "description": "Type of OS on the existing vhd" 
      } 
     }, 
     "vmSize": { 
      "type": "string", 
      "defaultValue": "Standard_D2", 
      "metadata": { 
       "description": "Size of the VM" 
      } 
     }, 
     "vmName": { 
      "type": "string", 
      "metadata": { 
       "description": "Name of the VM" 
      } 
     } 
    }, 
    "variables": { 
     "api-version": "2015-06-15", 
     "addressPrefix": "10.0.0.0/16", 
     "subnetName": "Subnet", 
     "subnetPrefix": "10.0.0.0/24", 
     "publicIPAddressName": "specializedVMPublicIP", 
     "publicIPAddressType": "Dynamic", 
     "virtualNetworkName": "specializedVMVNET", 
     "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", 
     "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]", 
     "nicName": "specializedVMNic" 
    }, 
    "resources": [ 
     { 
      "apiVersion": "[variables('api-version')]", 
      "type": "Microsoft.Network/virtualNetworks", 
      "name": "[variables('virtualNetworkName')]", 
      "location": "[parameters('location')]", 
      "properties": { 
       "addressSpace": { 
        "addressPrefixes": [ 
         "[variables('addressPrefix')]" 
        ] 
       }, 
       "subnets": [ 
        { 
         "name": "[variables('subnetName')]", 
         "properties": { 
          "addressPrefix": "[variables('subnetPrefix')]" 
         } 
        } 
       ] 
      } 
     }, 
     { 
      "apiVersion": "[variables('api-version')]", 
      "type": "Microsoft.Network/networkInterfaces", 
      "name": "[variables('nicName')]", 
      "location": "[parameters('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('api-version')]", 
      "type": "Microsoft.Network/publicIPAddresses", 
      "name": "[variables('publicIPAddressName')]", 
      "location": "[parameters('location')]", 
      "properties": { 
       "publicIPAllocationMethod": "[variables('publicIPAddressType')]" 
      } 
     }, 
     { 
      "apiVersion": "[variables('api-version')]", 
      "type": "Microsoft.Compute/virtualMachines", 
      "name": "[parameters('vmName')]", 
      "location": "[parameters('location')]", 
      "dependsOn": [ 
       "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 
      ], 
      "properties": { 
       "hardwareProfile": { 
        "vmSize": "[parameters('vmSize')]" 
       }, 
       "storageProfile": { 
        "osDisk": { 
         "name": "[concat(parameters('vmName'),'-osDisk')]", 
         "osType": "[parameters('osType')]", 
         "caching": "ReadWrite", 
         "vhd": { 
          "uri": "[parameters('osDiskVhdUri')]" 
         }, 
         "createOption": "Attach" 
        } 
       }, 
       "networkProfile": { 
        "networkInterfaces": [ 
         { 
          "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 
         } 
        ] 
       } 
      } 
     } 
    ] 
} 

Antwort

1

Der beste Weg, Dinge wie diese, um herauszufinden, ist durch die templates stecken, bis Sie finden, was Sie brauchen!

So nach this Vorlage, erhalten Sie eine Verfügbarkeit erstellen wie dieses Set

"resources": [ 
    { 
    "type": "Microsoft.Compute/availabilitySets", 
    "name": "availabilitySet1", 
    "apiVersion": "2015-06-15", 
    "location": "[parameters('location')]", 
    "properties": { 
     "platformFaultDomainCount": "3", 
     "platformUpdateDomainCount": "20" 
    } 
    } 
] 

und dann (nach this) Sie es wie diese verwenden

"apiVersion": "[variables('apiVersion')]", 
"type": "Microsoft.Compute/virtualMachines", 
"name": "[concat('myvm', copyIndex())]", 
"location": "[variables('location')]", 
"copy": { 
    "name": "virtualMachineLoop", 
    "count": "[parameters('numberOfInstances')]" 
}, 
"dependsOn": [ 
    "[concat('Microsoft.Network/networkInterfaces/', 'nic', copyindex())]", 
    "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]" 
], 
"properties": { 
    "availabilitySet": { 
    "id": "[resourceId('Microsoft.Compute/availabilitySets', variables('availabilitySetName'))]" 
    }, 
0

Sie würden werden müssen, suchen der Microsoft.Compute/availabilitySets-Ressourcenanbieter, hier ist ein Beispiel-JSON aus einer meiner Vorlagen.

"resources": [ 
{ 
    "type": "Microsoft.Compute/availabilitySets", 
    "name": "availabilitySet1", 
    "apiVersion": "2015-06-15", 
    "location": "[parameters('location')]", 
    "properties": { 
    "platformFaultDomainCount": "3", 
    "platformUpdateDomainCount": "20" 
    } 
} 
] 

Sie müssen dann die availabilitySet Eigenschaft des virtualMachines Ressourcenanbieter verwenden, um die VMs auf die Verfügbarkeit Satz hinzuzufügen. Stellen Sie sicher, dass Sie dependsOn verwenden, um sicherzustellen, dass das Verfügbarkeitsset vor der VM erstellt wird. Als ein Beispiel, wenn Sie sich darauf mit Namen beziehen:

"properties": { 
     "hardwareProfile": { "vmSize": "Standard_A0" }, 
     "networkProfile": ..., 
     "availabilitySet": { "id": "availabilitySet1" }, 
} 
Verwandte Themen