如何同时在 Azure VM 上运行 2 个 VM 自定义脚本扩展 [英] How to run a 2 VM custom script extensions on Azure VM at the same time

查看:27
本文介绍了如何同时在 Azure VM 上运行 2 个 VM 自定义脚本扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ARM 模板创建了一个 Azure VM,并希望在部署 VM 后在同一 VM 上运行 2 个 VM 脚本扩展.

I have create a Azure VM using ARM template and want to run a 2 VM script extensions on the same VM after VM is deployed.

如何使用ARM模板实现?

How can I achieve using the ARM template?

 {
        "apiVersion": "[variables('resourceDeploymentApiVersion')]",
        "name": "[variables('vmTemplateName')]",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('vmGroupName')]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[variables('vmTemplateURL')]"
            },
            "parameters": {},
        }
     }
 {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(variables('vmName'),'/install-script')]",
        "apiVersion": "[variables('computeApiVersion')]",
        "location": "[variables('location')]",
        "dependsOn": [
            "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
        ],
        "properties": {
            "publisher": "Microsoft.Azure.Extensions",
            "type": "CustomScript",
            "typeHandlerVersion": "2.0",
            "autoUpgradeMinorVersion": true,
            "forceUpdateTag": "v.1.0",
            "settings": {
               "fileUris": ["[variables('installScript')]"]
            },
            "protectedSettings":{
                "commandToExecute": "[concat('bash config.sh', ' ', parameters('key'))]"
            }
        }
    },



    {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(variables('vmName'),'/install-script')]",
            "apiVersion": "[variables('computeApiVersion')]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
            ],
            "properties": {
                "publisher": "Microsoft.Azure.Extensions",
                "type": "CustomScript",
                "typeHandlerVersion": "2.0",
                "autoUpgradeMinorVersion": true,
                "forceUpdateTag": "v.1.1",
                "settings": {
                   "fileUris": ["[variables('installScript1')]"]
                },
                "protectedSettings":{
                    "commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'))]"
                }
            }
        },

更新:-

目前我在与下面相同的扩展名中运行 config.sh 和 config1.sh.但它正在一个接一个地运行.我希望使用扩展同时启动 config.sh 和 config1.sh.

Currently I am running config.sh and config1.sh in the same extension as below. But it is running one after another. I want both config.sh and config1.sh to be started at same time using the extension.

{
                "type": "Microsoft.Compute/virtualMachines/extensions",
                "name": "[concat(variables('vmName'),'/install-script')]",
                "apiVersion": "[variables('computeApiVersion')]",
                "location": "[variables('location')]",
                "dependsOn": [
                    "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
                ],
                "properties": {
                    "publisher": "Microsoft.Azure.Extensions",
                    "type": "CustomScript",
                    "typeHandlerVersion": "2.0",
                    "autoUpgradeMinorVersion": true,
                    "forceUpdateTag": "v.1.1",
                    "settings": {
                       "fileUris": ["[variables('installScript1')]"]
                    },
                    "protectedSettings":{
                        "commandToExecute": "[concat('bash config1.sh', ' ', parameters('key1'), ' ', '&&', ' ', 'bash config.sh', ' ', parameters('key'))]"
                    }
                }
            },

推荐答案

实际上,如果使用 powershell cmdlet,自定义扩展无法同时执行.但是可以在模板中设置,一次性执行.

Actually, the custom extension cannot execute at the same time if you use powershell cmdlet. But it can be set in a template and execute at one time.

当我看到您的模板时,您将两个扩展名设置为相同的名称.您可以更改其中之一.然后像这样向其中一个添加一个dependsOn:

When I see your template, you set the two extensions with the same name. You can change one of them. Then add a dependsOn to one of them just like this:

"dependsOn":[  
     "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'),'/', 'install-script')]"
  ],

您可以查看此链接.和你很像.

You can take a look at this link. It's similar to you.

这篇关于如何同时在 Azure VM 上运行 2 个 VM 自定义脚本扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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