azure - 在azure ARM中输出VM的私有(private)IP

标签 azure automation cloud azure-resource-manager

我正在 ARM 模板中使用 copyindex() 启动多个 Azure VM。这是我正在使用的资源:

{
  "apiVersion": "[variables('apiVersion')]",
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[concat(parameters('vmDnsPrefixClientNode'),copyIndex(1))]",
  "location": "[resourceGroup().location]",
  "copy": {
        "name": "virtualMachineLoop",
        "count": "[parameters('vmInstancesClientNode')]"
    },
  "dependsOn": [
    "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'),copyindex(1))]",
        "[concat('Microsoft.Network/networkInterfaces/', parameters('vmDnsPrefixClientNode'),copyindex(1),'-nic')]"
  ],
  "properties": {
    "hardwareProfile": {
      "vmSize": "[parameters('vmSizeClientNode')]"
    },
    "osProfile": {
      "computername": "[concat(parameters('vmDnsPrefixClientNode'), copyIndex(1))]",
      "adminUsername": "[parameters('username')]",
      "adminPassword": "[parameters('password')]"
    },
    "storageProfile": {
      "imageReference": {
        "publisher": "[variables('imagePublisher')]",
        "offer": "[variables('imageOffer')]",
        "sku": "[variables('ubuntuOSVersion')]",
        "version": "latest"
      },
      "osDisk": {
        "name": "osdisk1",
        "vhd": {
          "uri": "[concat('http://',variables('storageAccountName'),copyindex(1),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',parameters('vmDnsPrefixClientNode'),copyIndex(1),'-osdisk1.vhd')]"
        },
        "caching": "ReadWrite",
        "createOption": "FromImage"
      },
      "dataDisks": [
        {
          "name": "datadisk1",
          "diskSizeGB": "10",
          "lun": 0,
          "vhd": {
            "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'),copyindex(1)), variables('apiVersion')).primaryEndpoints.blob, variables('vmDataContainerName'),'/',parameters('vmDnsPrefixClientNode'),copyIndex(1),'-',variables('dataDisk1VhdName'),'.vhd')]"
          },
          "createOption": "Empty"
        }
      ]
    },
    "networkProfile": {
      "networkInterfaces": [
        {
          "id": "[resourceId('Microsoft.Network/networkInterfaces',concat(parameters('vmDnsPrefixClientNode'),copyindex(1),'-nic'))]"
        }
      ]
    }
  }
},

我尝试过类似的方法,但不起作用

"outputs": {
  "privateIP": {
    "value": "[reference(concat(parameters('vmDnsPrefixClientNode'),copyindex(1),'-nic'),providers('Microsoft.Network', 'privateIPAddresses').apiVersions[0]).dnsSettings.fqdn]",
    "type": "string",
    "copy": {
        "name": "vmNic",
        "count": "[parameters('vmInstancesClientNode')]"
    }
  }
}

有人知道如何在输出中获取私有(private) IP 或内部 FQDN 吗?

最佳答案

我在模板中使用了以下代码从网络接口(interface)获取私有(private) IP 地址。

"outputs":{
    "networkInterface":{
        "value": "[reference(resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName')),'2016-09-01')]",
        "type": "object"
    }
}

获得输出后,您可以在

处找到 IP 地址

outputs.networkInterface.value.ipConfigurations[0].properties.privateIPAddress

以及

的 DNS 后缀

outputs.networkInterface.value.dnsSettings.internalDomainNameSuffix

关于azure - 在azure ARM中输出VM的私有(private)IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39580630/

相关文章:

c# - 在 Windows Azure 中打开和关闭实例的代码

nginx - 我们可以使用 HAproxy 负载均衡器和 nginx 作为服务器吗?

.net - 处理来自 Azure 服务总线的大量消息的最佳方法

java - org.openqa.selenium.ElementNotInteractableException : Cannot click on element

java - 使用java在excel中的两列中写入多条记录

java - 对象未突出显示,尽管它在 Chrome 开发人员工具中显示为唯一

mysql - 从云服务器改为专用服务器会提高MySQL性能吗?

powershell - 用于获取所有虚拟机的正常运行时间的 Azure powershell 命令

azure - id token 的自定义安全属性

php - 我尝试使用 PHP 连接到 Azure 服务总线队列,但不断收到此错误