我正在尝试使用Powershell DSC安装URL重写器,但它一直失败。当我删除安装重写器的步骤时,脚本成功。

我的设置使用的是Visual Studio Team Services(VSTS)构建和发布管道,我执行一个ARM模板来创建一个缩放集,指向一个powershell dsc脚本。

"extensionProfile": {
    "extensions": [
    {
        "name": "Microsoft.Powershell.DSC",
        "properties": {
            "publisher": "Microsoft.Powershell",
            "type": "DSC",
            "typeHandlerVersion": "2.72",
            "autoUpgradeMinorVersion": true,
            "forceUpdateTag": "[parameters('dscVmssUpdateTagVersion')]",
            "settings": {
                "configuration": {
                    "url": "https://myblobname.blob.core.windows.net/dsc/scalesetSetup.zip",
                    "script": "prepareServer.ps1",
                    "function": "PrepareServer"
                },
                "configurationArguments": {
                        "nodeName": "localhost",
                        "envName": "[parameters('envName')]"
                    }
                }
            }
        }
    ]
}

在此脚本中,我将启用Windows功能,安装Web Deploy和URL Rewriter。当未安装重写器时,一切正常,但是当我通过以下两种方式将其重新添加时,一切都会失败。

DSC脚本实际上看起来像:
Configuration PrepareServer
{

Param ( [string] $nodeName, [string] $envName )

Import-DscResource -ModuleName PSDesiredStateConfiguration

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

    ## other features ...

    Script DownloadWebDeploy
    {
        TestScript = {
            Test-Path "C:\WindowsAzure\WebDeploy_amd64_en-US.msi"
        }
        SetScript ={
            $source = "https://download.microsoft.com/download/0/1/D/01DC28EA-638C-4A22-A57B-4CEF97755C6C/WebDeploy_amd64_en-US.msi"
            $dest = "C:\WindowsAzure\WebDeploy_amd64_en-US.msi"
            Invoke-WebRequest $source -OutFile $dest
        }
        GetScript = {@{Result = "DownloadWebDeploy"}}
        DependsOn = "[WindowsFeature]WebServerRole"
    }
    Package InstallWebDeploy
    {
        Ensure = "Present"
        Path  = "C:\WindowsAzure\WebDeploy_amd64_en-US.msi"
        Name = "Microsoft Web Deploy 3.6"
        ProductId = "{6773A61D-755B-4F74-95CC-97920E45E696}"
        Arguments = "ADDLOCAL=ALL"
        DependsOn = "[Script]DownloadWebDeploy"
    }
    Service StartWebDeploy
    {
        Name = "WMSVC"
        StartupType = "Automatic"
        State = "Running"
        DependsOn = "[Package]InstallWebDeploy"
    }

    ## attempt to install UrlRewrite here
}

我直接从quickstart示例中获取了此信息:
    Package UrlRewrite
    {
        #Install URL Rewrite module for IIS
        DependsOn = "[WindowsFeature]WebServerRole"
        Ensure = "Present"
        Name = "IIS URL Rewrite Module 2"
        Path = "http://download.microsoft.com/download/6/7/D/67D80164-7DD0-48AF-86E3-DE7A182D6815/rewrite_2.0_rtw_x64.msi"
        Arguments = "/quiet"
        ProductId = "EB675D0A-2C95-405B-BEE8-B42A65D23E11"
    }

上面的失败以一个令人讨厌的模糊错误
{
  "status": "Failed",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource operation completed with terminal provisioning state 'Failed'.",
    "details": [
      {
        "code": "VMExtensionProvisioningError",
        "message": "VM has reported a failure when processing extension 'Microsoft.Powershell.DSC'. Error message: \"DSC Configuration 'PrepareServer' completed with error(s). Following are the first few: PowerShell DSC resource MSFT_PackageResource  failed to execute Set-TargetResource functionality with error message: The return code 1603 was not expected. Configuration is likely not correct  The SendConfigurationApply function did not succeed.\"."
      }
    ]
  }
}

所以我试图以这种方式下载并安装软件包
#download works, install does not
Script DownloadUrlRewrite
{
    TestScript = {
        Test-Path "C:\WindowsAzure\rewrite_2.0_rtw_x64.msi"
    }
    SetScript ={
        $source = "http://download.microsoft.com/download/6/7/D/67D80164-7DD0-48AF-86E3-DE7A182D6815/rewrite_2.0_rtw_x64.msi"
        $dest = "C:\WindowsAzure\rewrite_2.0_rtw_x64.msi"
        Invoke-WebRequest $source -OutFile $dest
    }
    GetScript = {@{Result = "DownloadUrlRewrite"}}
    DependsOn = "[WindowsFeature]WebServerRole"
}
Package InstallUrlRewrite
{
    Ensure = "Present"
    Path  = "C:\WindowsAzure\rewrite_2.0_rtw_x64.msi"
    Name = "IIS URL Rewrite Module 2"
    ProductId = "{EB675D0A-2C95-405B-BEE8-B42A65D23E11}"
    Arguments = "/quiet"
    DependsOn = "[Script]DownloadUrlRewrite"
}

在这种情况下,下载工作正常,并且在目录中找到了msi。但是,它没有安装url重写器,并且部署失败。

我添加了一个用于记录的参数,但不确定错误仍然存​​在。
Package UrlRewrite
    {
        #Install URL Rewrite module for IIS
        DependsOn = "[WindowsFeature]WebServerRole"
        Ensure = "Present"
        Name = "IIS URL Rewrite Module 2"
        Path = "http://download.microsoft.com/download/6/7/D/67D80164-7DD0-48AF-86E3-DE7A182D6815/rewrite_2.0_rtw_x64.msi"
        Arguments = '/L*V "C:\WindowsAzure\urlrewriter.txt" /quiet'
        ProductId = "EB675D0A-2C95-405B-BEE8-B42A65D23E11"
    }

这是与错误相关的日志的一部分,似乎没有其他相关的内容。
Action ended 23:54:42: AppSearch. Return value 1.
Action start 23:54:42: FindRelatedProducts.
MSI (s) (C4:B4) [23:54:42:549]: Doing action: LaunchConditions
Action ended 23:54:42: FindRelatedProducts. Return value 1.
Action start 23:54:42: LaunchConditions.
MSI (s) (C4:B4) [23:54:42:549]: Product: IIS URL Rewrite Module 2 -- IIS
    Version 7.0 or greater is required to install IIS URL Rewrite Module 2.

IIS Version 7.0 or greater is required to install IIS URL Rewrite Module 2.
Action ended 23:54:42: LaunchConditions. Return value 3.
Action ended 23:54:42: INSTALL. Return value 3.

... bunch of Property(S): stuffs...

MSI (s) (C4:B4) [23:54:42:565]: Note: 1: 1708
MSI (s) (C4:B4) [23:54:42:565]: Product: IIS URL Rewrite Module 2 -- Installation failed.

MSI (s) (C4:B4) [23:54:42:565]: Windows Installer installed the product. Product
Name: IIS URL Rewrite Module 2. Product Version: 7.2.2. Product Language: 1033. Manufacturer: Microsoft Corporation. Installation success or error status: 1603.

MSI (s) (C4:B4) [23:54:42:565]: Deferring clean up of packages/files, if any exist
MSI (s) (C4:B4) [23:54:42:565]: MainEngineThread is returning 1603

我试着只是手动安装它,以查看会发生什么,并且出现相同的消息却出错,但是很明显已经安装了IIS。现在我想知道是2016-Datacenter还是IIS 10是问题所在。

powershell - URL重写器Powershell DSC-LMLPHP

最佳答案

似乎快速入门模板中使用的URL Rewrite版本不适用于最新的2016-Datacenter。

"imageReference": {
    "publisher": "MicrosoftWindowsServer",
    "offer": "WindowsServer",
    "sku": "2016-Datacenter",
    "version": "latest"
}

使用此版本似乎可行
## IIS URL Rewrite module download and install
Package UrlRewrite
{
    #Install URL Rewrite module for IIS
    DependsOn = "[WindowsFeature]WebServerRole"
    Ensure = "Present"
    Name = "IIS URL Rewrite Module 2"
    Path = "http://download.microsoft.com/download/D/D/E/DDE57C26-C62C-4C59-A1BB-31D58B36ADA2/rewrite_amd64_en-US.msi"
    Arguments = '/L*V "C:\WindowsAzure\urlrewriter.txt" /quiet'
    ProductId = "38D32370-3A31-40E9-91D0-D236F47E3C4A"
}

08-07 14:44