如何在具有相同模板的HDI群集的VM扩展脚本中添加dependsOn

时间:2018-07-20 07:57:45

标签: azure arm-template azure-deployment

我要执行以下操作

  1. 并行创建HDI群集(资源组1)和2个VM(资源组2)
  2. 在部署HDI和VM1之后在VM1中运行扩展脚本
  3. 在部署VM1和VM2之后在VM2中运行扩展脚本

我遇到如下错误

  

错误:部署模板验证失败:“资源   在以下位置未定义“ Microsoft.Resources / deployments / clusterTemplate”   模板。请参阅https://aka.ms/arm-template以了解用法   详细信息。”

我该如何解决这个问题?

{
        "apiVersion": "[variables('resourceDeploymentApiVersion')]",
        "name":"[variables('clusterTemplateName')]",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('clusterResourceGroupName')]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[variables('clusterTemplateURL')]"
            },
            "parameters": {
                "clusterName": { "value": "[parameters('clusterName')]" 
            }
        }

    },          
    {
        "apiVersion": "[variables('resourceDeploymentApiVersion')]",
        "name": "[variables('vmTemplateName')]",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('vmResourceGroupName')]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[variables('vmTemplateURL')]"
            },
            "parameters": {
                "appid": { "value": "[parameters('appid')]" }
            }
        }             
    },

    {
        "apiVersion": "[variables('resourceDeploymentApiVersion')]",
        "name": "[variables('vmTemplateName1')]",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('vmResourceGroupName')]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[variables('vmTemplateURL1')]"
            },
            "parameters": {
                "appid": { "value": "[parameters('appid')]" }
            }
        }             
    },
 {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat('vmName','/install-script')]",
        "apiVersion": "[variables('computeApiVersion')]",
        "location": "[variables('location')]",  
        "dependsOn": [
            "[resourceId('Microsoft.Resources/deployments', variables('clusterTemplateName'))]",
            "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]"
        ],
        "properties": {
            "publisher": "Microsoft.Azure.Extensions",
            "type": "CustomScript",
            "typeHandlerVersion": "2.0",
            "autoUpgradeMinorVersion": true,
            "settings": {
               "fileUris": ["[variables('installScript')]"]
            },
            "protectedSettings":{
                "commandToExecute": "[concat('bash init.sh', ' ', parameters('appId'))]"
            }
        }
    },{
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat('vmName','/install-script')]",
        "apiVersion": "[variables('computeApiVersion')]",
        "location": "[variables('location')]",  
        "dependsOn": [
            "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName'))]",
            "[resourceId('Microsoft.Resources/deployments', variables('vmTemplateName1'))]"
        ],
        "properties": {
            "publisher": "Microsoft.Azure.Extensions",
            "type": "CustomScript",
            "typeHandlerVersion": "2.0",
            "autoUpgradeMinorVersion": true,
            "settings": {
               "fileUris": ["[variables('installScript')]"]
            },
            "protectedSettings":{
                "commandToExecute": "[concat('bash init.sh', ' ', parameters('appId'))]"
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

我可以通过在resourceId中使用群集资源组名称来解决此问题

之前:-

        "[resourceId('Microsoft.Resources/deployments', variables('clusterTemplateName'))]",

之后:-

    "dependsOn": [
        "[resourceId(parameters('clusterResourceGroupName'), 'Microsoft.Resources/deployments', variables('clusterTemplateName'))]",