代码之家  ›  专栏  ›  技术社区  ›  Galet

如何同时在Azure虚拟机上运行2虚拟机自定义脚本扩展

  •  1
  • Galet  · 技术社区  · 6 年前

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

    如何使用ARM模板实现?

     {
            "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。

    {
                    "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'))]"
                        }
                    }
                },
    
    1 回复  |  直到 6 年前
        1
  •  -1
  •   Charles Xu    6 年前

    实际上,如果使用powershell cmdlet,则无法同时执行自定义扩展。但它可以在模板中设置并同时执行。

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

    你可以看看这个 link . 和你很相似。

    推荐文章