Azure Arm模板的Bootstrap DSC扩展

时间:2017-10-06 11:17:29

标签: powershell azure dsc

我有一个ARM模板,它执行Desired State Configuration扩展以安装和配置IIS。但是我需要安装和配置一些需要我已安装其他工具的区域。

手臂模板

{
        "name": "Microsoft.Powershell.DSC",
        "properties": {
            "publisher": "Microsoft.Powershell",
            "type": "DSC",
            "typeHandlerVersion": "2.20",
            "autoUpgradeMinorVersion": true,
            "forceUpdateTag":"v.4.2",                                   
            "settings": {                                       
                "wmfVersion": "latest",
                "configuration": {
                    "url": "[concat(variables('dscArtifactsLocation'), '/', variables('dscExtensionArchiveFolder'),'/IISInstall.ps1.zip')]",
                    "script": "IISInstall.ps1",
                    "function": "IISInstall"
                },
                "configurationArguments": {
                    "nodeName": "localhost"
                }
            },
            "protectedSettings": {
                "configurationUrlSasToken": "?TOKEN"
            }
        }
    }

IISInstall.ps1

   Node $nodeName
    { 
        WindowsFeature IIS 
        { 
            Ensure = "Present" 
            Name = "Web-Server"                       
        } 

        WindowsFeature AspNet45
        {
            Ensure = "Present"
            Name= "Web-Asp-Net45"
        }
    }

例如我希望能够使用xWebAdministration,但这需要我先安装它才能打电话

Import-DscResource -ModuleName xWebAdministration

另外我需要安装IISUrlRewrite v2,计划是巧妙地使用,但这也需要安装才能用它来安装程序。是否可以“引导”DSC执行?

1 个答案:

答案 0 :(得分:1)

由于scaleset扩展并行运行,目前似乎不支持此功能。可能首选的选项是在通过custom script extension

运行的PowerShell脚本中实现引导程序

您可以创建存储在blobstorage中的多个单独的PowerShell脚本,并使用&&分隔它们 这是通过部署dotnet.core的powershell before向scaleset实例添加新硬盘的示例。

{ "name": "[concat(variables('vmNodeTypeAppName'),'_InitializeVM')]", "properties": { "publisher": "Microsoft.Compute", "settings": { "fileUris": ["https://dot.net/v1/dotnet-install.ps1"] }, "typeHandlerVersion": "1.8", "autoUpgradeMinorVersion": true, "protectedSettings": { "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -Command \"Get-Disk | Where partitionstyle -eq 'raw' | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -DriveLetter F -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel DataDisk -Confirm:$false\" && powershell.exe -ExecutionPolicy Unrestricted -File dotnet-install.ps1 -SharedRuntime" }, "type": "CustomScriptExtension" } }