powershell - 适用于 Azure Arm 模板的 Bootstrap DSC 扩展

标签 powershell azure dsc

我有一个 ARM 模板,它执行所需状态配置扩展以安装和配置 IIS。但是,我需要安装和配置一些区域,这要求我已经安装了其他工具。

ARM 模板

{
        "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,计划是使用 Chocolately,但这也需要安装才能使用它来安装程序。是否可以“引导”DSC 执行?

最佳答案

目前似乎不支持此功能,因为 scaleset 扩展并行运行。可能首选选项是在通过 custom script extension 运行的 powershell 脚本中实现 Bootstrap

您可以创建存储在 blobstorage 中的多个单独的 powershell 脚本,并使用 && 分隔调用它们 以下是在部署 dotnet.core 之前通过 powershell 将新 HDD 添加到规模集实例的示例。

{ “名称”:“[concat(变量('vmNodeTypeAppName'),'_InitializeVM')]”, “特性”: { "出版商": "微软.Compute", “设置”: { “fileUris”:[“https://dot.net/v1/dotnet-install.ps1”] }, "typeHandlerVersion": "1.8", “autoUpgradeMinorVersion”:true, “ protected 设置”:{ “执行命令”: “powershell.exe -ExecutionPolicy Unrestricted -Command\”获取磁盘|其中partitionstyle -eq 'raw' |初始化磁盘-分区样式MBR-PassThru |新分区-DriveLetter F-UseMaximumSize |格式卷 -FileSystem NTFS -NewFileSystemLabel DataDisk -Confirm:$false\"&& powershell.exe -ExecutionPolicy Unrestricted -File dotnet-install.ps1 -SharedRuntime" }, “类型”:“自定义脚本扩展” } }

关于powershell - 适用于 Azure Arm 模板的 Bootstrap DSC 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46604537/

相关文章:

powershell - -ErrorAction with Get-ADComputer 不隐藏错误

Azure Batch Pool启动任务从Blob FileShare下载资源文件

powershell - 如何将 PowerShell 表达式的结果注册到 DSC 的变量中?

azure - 如何通过传入 header 值限制对 Azure Web App 的访问?

azure - 连接到 Azure SQL 数据仓库时出现问题

PowerShell 5.0 DSC 和导入

powershell - 如何在nodeName中使用 "*"

arrays - Powershell 测试数组是否在一行中

regex - 替换不适用于正则表达式

powershell - 在带有参数的函数上使用 Invoke-Command -ScriptBlock