【问题标题】:Azure ARM Template - Running DSC script without triggering extension install?Azure ARM 模板 - 在不触发扩展安装的情况下运行 DSC 脚本?
【发布时间】:2019-03-13 17:53:23
【问题描述】:

我正在尝试部署具有两个 DC 的 Active Directory 林。我已成功部署 DC 并在两个 VM 上安装了 ADDS 功能。 “PDC”有一个运行和配置森林的 DSC 脚本,同样效果很好。我遇到的问题是尝试在第二个 DC 上运行第二个 DSC 脚本,该脚本运行 ADDS 配置以将 VM 提升为 DC 并将其加入林。我创建了一个由主模板调用的嵌套 JSON 模板。但我遇到了这个错误:

“操作系统类型 'Windows' 不支持每个处理程序多个 VMExtensions。VMExtension 'PrepareBDC' 处理程序 'Microsoft.Powershell.DSC' 已在输入中添加或指定。”

过去一个小时左右,我一直在互联网上寻找答案,但每个人似乎都在说同样的话……你不能两次安装相同的扩展程序。好的,我明白为什么这样做有意义,我的问题是我可以配置嵌套模板,使其不尝试安装扩展,而只使用 VM 上已安装的内容吗?

主模板sn-p:

{
    "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'))]"
            }
        }
    }
},

嵌套模板:

{
    "$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')]"
                    }
                }
            }
        }
    ]
}

【问题讨论】:

    标签: json azure templates dsc


    【解决方案1】:

    这个错误的意思正是它所说的:你不能拥有同一个扩展的多个副本,你需要做的是对虚拟机应用相同的扩展,所有的输入必须是相同的。你可以看看this example,它就是这样做的。此特定模板第二次安装扩展以将 bdc 加入域。

    但是,我不喜欢这种方法。我使用 Powershell DSC 来等待域被创建并一次性将 bdc 加入域。你会使用这个 powershell dsc sn-p:

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

    Here's一个完整的例子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      相关资源
      最近更新 更多