2

我正在尝试使用 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
}

我直接从一个快速入门示例中获取了这个:

    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。

在此处输入图像描述

4

1 回答 1

5

似乎快速入门模板中使用的 URL 重写版本不适用于 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"
}
于 2018-01-03T17:05:31.760 回答