如何为Windows和Linux使用一个ARM模板

时间:2018-04-20 12:37:05

标签: visual-studio azure virtual-machine arm-template

我正在尝试使用一个ARM模板在Azure中部署Windows和Linux VM。目前我能够成功部署两者,除了我不能使用额外的配置,而不会在Visual Studio中出现错误。当我选择构建Windows VM的选项时,有关于Linux配置的错误,并且Id必须删除整行。

"linuxConfiguration": {
                "disablePasswordAuthentication": "true",
                "ssh": {
                  "publicKeys": [
                    {
                      "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
                      "keyData": "REMOVED"
                    }
                  ]
                }

在StorageProfile中,我只是引用了ID。我有没有办法每次都不提出身份证?

"storageProfile": {
              "imageReference": {
                "id": "/subscriptions/91dc1292-e7af-4ae6-807f-aa5b88bf3b79/resourceGroups/DVOPS_DEV_ResourceGroup/providers/Microsoft.Compute/images/Rhel7singleDisk"
              },

CODE片段在

之下
        {
          "apiVersion": "2017-03-30",
          "type": "Microsoft.Compute/virtualMachines",
          "name": "[variables('vmName')]",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
          ],
          "properties": {
            "hardwareProfile": {
              "vmSize": "[parameters('vmSize')]"
            },
            "osProfile": {
              "computerName": "[parameters('customVmName')]",
              "adminUsername": "[parameters('adminUsername')]",
              "adminPassword": "[parameters('adminPassword')]",
              "linuxConfiguration": {
                "disablePasswordAuthentication": "true",
                "ssh": {
                  "publicKeys": [
                    {
                      "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
                      "keyData": "REMOVED"
                    }
                  ]
                }
              }
            },
/// HOW TO FIX THE STORAGE PROFILE 
            "storageProfile": {
              "imageReference": {
                "id": "/subscriptions/91dc1292-e7af-4ae6-807f-aa5b88bf3b79/resourceGroups/DVOPS_DEV_ResourceGroup/providers/Microsoft.Compute/images/Rhel7singleDisk"
              },
              "osDisk": {
                "name": "[concat(parameters('customVmName'),'-os')]",
                "createOption": "FromImage",
                "managedDisk": {
                  "storageAccountType": "[parameters('diskStorageType')]"
                }
              },
              "dataDisks": [
                {
                  "name": "[concat(parameters('customVmName'),'-dataDisk-0')]",
                  "lun": 0,
                  "diskSizeGB": 1023,
                  "createOption": "Empty",
                  "managedDisk": {
                    "storageAccountType": "[parameters('diskStorageType')]"
                  }
                }
              ]
            },

1 个答案:

答案 0 :(得分:0)

您可以使用变量来包含JSON块,这是我执行Windows / Linux选择的一部分

"variables": {
    "Ubuntu": {
        "publisher": "Canonical",
        "offer": "UbuntuServer",
        "sku": "16.04-LTS",
        "version": "latest"
    },
    "Windows": {
        "publisher": "MicrosoftWindowsServer",
        "offer": "WindowsServer",
        "sku": "2016-Datacenter-with-Containers",
        "version": "latest"
    },
    "imageReference": "[variables('Ubuntu')]"
},

"storageProfile": {
    "imageReference": "[variables('imageReference')]",

    },

就像那样,您可以根据需要创建尽可能多的JSON块,并在需要的地方交换它们