【问题标题】:Pass my just created VM's IP as an extension's parameter of the same VM将我刚刚创建的 VM 的 IP 作为同一 VM 的扩展参数传递
【发布时间】:2020-08-30 06:17:04
【问题描述】:

我创建了一个 ARM 模板,该模板部署了一个名为“VM1”的虚拟机,然后是该虚拟机的扩展;该扩展在某个 repo 上调用了一个 PowerShell 脚本,我正在成功地将一些参数传递给它。

我的问题是:如何在同一模板中正确传递虚拟机“VM1”的 IP 作为此扩展的参数?

{
          "type": "Microsoft.Compute/virtualMachines/extensions",
          "apiVersion": "2019-12-01",
          "name": "[concat(parameters('virtualMachines_VM_name'),'/', 'Mypowershell')]",
          "location": "[parameters('location')]",
         "dependsOn": [
            "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_VM_name'))]"
        ],
          "properties": {
              "publisher": "Microsoft.Compute",
              "type": "CustomScriptExtension",
              "typeHandlerVersion": "1.7",
              "autoUpgradeMinorVersion":true,
              "settings": {
                "fileUris": [
                  "https://raw.githubusercontent.com/********/********/master/powershell.ps1"
                ],
                "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File powershell.ps1', ' -database ', parameters('DataBaseName'), 
                ' -uid ', parameters('adminUsername'), ' -pwd ', parameters('adminPassword'), ' -dbserver ', parameters('servers_dbserver_name'), ' -vmip ', parameters('VM_IP'))]"
              }
          }}

仅作记录,在上面的代码中,我尝试将 VM 的 IP 作为 ARM 参数传递,但没有成功。

【问题讨论】:

    标签: json azure


    【解决方案1】:

    我意识到我的 powershell 文件在我的 repo 中,但在 VM 中运行,这就是扩展的作用,所以我可以在我的 powershwll 文件中放入以下行:

    $publicIp = (Invoke-RestMethod http://ipinfo.io/json).ip
    

    所以我不必在我的 ARM 模板中将其作为参数传递,以便在我的 powershell 中使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 2020-01-16
      • 1970-01-01
      • 2022-07-06
      • 1970-01-01
      • 2023-03-06
      • 2013-03-27
      相关资源
      最近更新 更多