如何在 Azure ARM 模板中设置环境变量 [英] How to set environment variables in Azure ARM templates

查看:31
本文介绍了如何在 Azure ARM 模板中设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 ARM 模板中为我的部署设置环境,以确保环境在机器之间是相同的.有没有办法为使用ARM模板创建的虚拟机设置环境变量?

I want to set the environment on my deployments in the ARM-template to guarantee the environment is the same across machines. Is there a way to set environment variables for a virtual machine created with an ARM template?

推荐答案

Windows

您可以使用自定义脚本扩展 在部署时调用 SETX.将嵌套资源添加到 VM 资源的 resources 数组.本示例调用目标机器上的 SETX MyEnvironmentPrefix (environmentPrefix-parameter-value)/m:

Windows

You can use a Custom Script Extension to invoke SETX at deployment time. Add a nested resource to the resources array of your VM resource. This example invokes SETX MyEnvironmentPrefix (environmentPrefix-parameter-value) /m on the target machine:

{
    "apiVersion": "2017-12-01",
    "type": "extensions",
    "name": "SetEnvironmentVar",
    "comments": "Sets the MyEnvironmentPrefix system env var",
    "location": "[resourceGroup().location]",
    "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
    ],
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.9",
        "autoUpgradeMinorVersion": true,
        "settings": {
            "commandToExecute": "[concat('SETX MyEnvironmentPrefix ', parameters('environmentPrefix'), ' /m')]"
        }
    }
}

这篇关于如何在 Azure ARM 模板中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆