简体   繁体   English

Azure ARM模板-运行DSC脚本而不触发扩展安装?

[英]Azure ARM Template - Running DSC script without triggering extension install?

I am trying to deploy a Active Directory forest with two DCs. 我正在尝试部署具有两个DC的Active Directory林。 I've managed to deploy the DCs and install the ADDS features on both VMs. 我已经设法在两个VM上部署了DC并安装了ADDS功能。 The "PDC" had a DSC script that runs and configures the forest, again that works great. “ PDC”具有运行和配置目录林的DSC脚本,同样效果很好。 The issue I have is trying to run a second DSC script on the second DC, this script runs the ADDS configuration to promote the VM to a DC and join it to the forest. 我遇到的问题是尝试在第二个DC上运行第二个DSC脚本,此脚本运行ADDS配置以将VM升级为DC并将其加入目录林。 I've created a nested JSON template that gets called by the main template. 我创建了一个嵌套的JSON模板,该模板由主模板调用。 But I am hitting this error: 但是我遇到了这个错误:

"Multiple VMExtensions per handler not supported for OS type 'Windows'. VMExtension 'PrepareBDC' with handler 'Microsoft.Powershell.DSC' already added or specified in input." “操作系统类型'Windows'不支持每个处理程序多个VMExtensions。输入中已添加或指定了带有处理程序'Microsoft.Powershell.DSC'的VMExtension'PrepareBDC'。”

I've spent the last hour or so whizzing around the internet looking for answers and everyone seems to say the same thing...you can't install the same extension twice. 我花了大约一个小时的时间在互联网上闲逛,寻找答案,每个人似乎都在说同样的话……您不能两次安装相同的扩展程序。 Ok, I can see why that would make sense, my question is can I configure the nested template so it doesn't try and install the extension, just uses what's already installed on the VM? 好的,我明白了为什么这样有意义,我的问题是我可以配置嵌套模板,以便它不尝试安装扩展,而仅使用VM上已安装的扩展吗?

Main template snippet: 主模板代码段:

{
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(variables('dc2name'), '/PrepareDC2AD')]",
    "apiVersion": "2018-06-01",
    "location": "[resourceGroup().location]",
    "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', variables('dc2name'))]"
    ],
    "properties": {
        "publisher": "Microsoft.Powershell",
        "type": "DSC",
        "typeHandlerVersion": "2.19",
        "autoUpgradeMinorVersion": true,
        "settings": {
            "ModulesUrl": "[concat(parameters('Artifacts Location'), '/dsc/PrepareADBDC.zip', parameters('Artifacts Location SAS Token'))]",
            "ConfigurationFunction": "PrepareADBDC.ps1\\PrepareADBDC",
            "Properties": {
                "DNSServer": "[variables('dc1ipaddress')]"
            }
        }
    }
},
{
    "name": "ConfiguringDC2",
    "type": "Microsoft.Resources/deployments",
    "apiVersion": "2016-09-01",
    "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/',variables('dc1name'),'/extensions/CreateADForest')]",
        "[concat('Microsoft.Compute/virtualMachines/',variables('dc2name'),'/extensions/PrepareDC2AD')]"
    ],
    "properties": {
        "mode": "Incremental",
        "templateLink": {
            "uri": "[concat(parameters('Artifacts Location'), '/nestedtemplates/configureADBDC.json', parameters('Artifacts Location SAS Token'))]",
            "contentVersion": "1.0.0.0"
        },
        "parameters": {
            "adBDCVMName": {
                "value": "[variables('dc2name')]"
            },
            "location": {
                "value": "[resourceGroup().location]"
            },
            "adminUsername": {
                "value": "[parameters('Administrator User')]"
            },
            "adminPassword": {
                "value": "[parameters('Administrator Password')]"
            },
            "domainName": {
                "value": "[parameters('Domain Name')]"
            },
            "adBDCConfigurationFunction": {
                "value": "ConfigureADBDC.ps1\\ConfigureADBDC"
            },
            "adBDCConfigurationModulesURL": {
                "value": "[concat(parameters('Artifacts Location'), '/dsc/ConfigureADBDC.zip', parameters('Artifacts Location SAS Token'))]"
            }
        }
    }
},

The nested template: 嵌套模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "adBDCVMName": {
            "type": "string"
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "adminUsername": {
            "type": "string"
        },
        "adminPassword": {
            "type": "securestring"
        },
        "domainName": {
            "type": "string"
        },
        "adBDCConfigurationFunction": {
            "type": "string"
        },
        "adBDCConfigurationModulesURL": {
            "type": "string"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(parameters('adBDCVMName'),'/PrepareBDC')]",
            "apiVersion": "2016-03-30",
            "location": "[parameters('location')]",
            "properties": {
                "publisher": "Microsoft.Powershell",
                "type": "DSC",
                "typeHandlerVersion": "2.21",
                "autoUpgradeMinorVersion": true,
                "forceUpdateTag": "1.0",
                "settings": {
                    "modulesURL": "[parameters('adBDCConfigurationModulesURL')]",
                    "wmfVersion": "4.0",
                    "configurationFunction": "[parameters('adBDCConfigurationFunction')]",
                    "properties": {
                        "domainName": "[parameters('domainName')]",
                        "adminCreds": {
                            "userName": "[parameters('adminUsername')]",
                            "password": "privateSettingsRef:adminPassword"
                        }
                    }
                },
                "protectedSettings": {
                    "items": {
                        "adminPassword": "[parameters('adminPassword')]"
                    }
                }
            }
        }
    ]
}

this error means exactly what it says: you cannot have multiple copies of the same extension, what you need to do is apply the same extension to the vm, all the inputs have to be the same. 该错误的含义与所说明的完全相同:您不能拥有同一扩展名的多个副本,您需要做的是将同一扩展名应用于vm,所有输入必须相同。 you can have a look at this example which does exactly that. 您可以看一下这个示例 This particular template installs the extension for the second time to join bdc to the domain. 此特定模板第二次安装扩展,以将bdc加入域。

But, I don't like that approach. 但是,我不喜欢这种方法。 I use Powershell DSC to just wait for the domain to get created and join the bdc to the domain in one go. 我使用Powershell DSC来等待域创建,然后将bdc一次性加入该域。 you would use this powershell dsc snippet: 您将使用以下powershell dsc代码段:

xWaitForADDomain DscForestWait {
    DomainName           = $DomainName
    DomainUserCredential = $DomainCreds
    RetryCount           = $RetryCount
    RetryIntervalSec     = $RetryIntervalSec
}

Here's a complete example 这是一个完整的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM