2

I'm trying to get the URL Rewriter installed using Powershell DSC and it keeps failing. When I remove the step for installing rewriter, the script succeeds.

My setup is using Visual Studio Team Services (VSTS) build and release pipeline I execute an ARM template to create a scale set, pointing to a powershell dsc script.

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

in this script, I'm enabling windows features, installing Web Deploy and URL Rewriter. Everything works when rewriter is not being installed, but fails when I add it back in either of the following ways.

The DSC script effectively looks like:

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
}

I took this directly from a quickstart example:

    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"
    }

The above fails with an annoyingly vague error

{
  "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.\"."
      }
    ]
  }
}

So I tried to just download and install the package this way

#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"
}

In this case, the download does work and the msi is found in the directory. However, it does not install the url rewriter and fails deployment.

I added an argument for logging, but not sure what the error is still.

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"
    }

Here is a part of the log related to errors, nothing else seemed relevant.

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

I tried to just manually install it to see what would happen and it did error with the same message, but clearly IIS is installed. Now I'm wondering if it's 2016-Datacenter or IIS 10 that is the problem.

enter image description here

MPavlak
  • 2,133
  • 1
  • 23
  • 38
  • 1603 is usually an msi failure code. Search the log file for 'return value 3' – Maximilian Burszley Jan 02 '18 at 22:12
  • where is the log stored? I am seeing the error in Azure's notification area. – MPavlak Jan 02 '18 at 22:14
  • Pass a `/log:path` arg with /quiet. – Maximilian Burszley Jan 02 '18 at 22:15
  • i added the log argument, but it is now just hanging on the update. i'll try to deploy a new resource and see if I have better luck. – MPavlak Jan 02 '18 at 22:40
  • I looked up the msi arguments for logging and changed my script to Arguments = "/L*V 'C:\WindowsAzure\urlrewriter.txt' /quiet" but no file was generated – MPavlak Jan 02 '18 at 23:48
  • flipping the quotes worked, but the file doesn't tell me much. updated answer – MPavlak Jan 03 '18 at 00:01
  • Looks like you don't have IIS7+: `IIS Version 7.0 or greater is required to install IIS URL Rewrite Module 2.` – Maximilian Burszley Jan 03 '18 at 01:57
  • isnt' that what webserver role does? I definitely have iis installed :) – MPavlak Jan 03 '18 at 15:49
  • You may need more than just `Web-Server`. [This script](https://github.com/AvyanConsultingCorp/PCI_Reference_Architecture/blob/master/artifacts/configurationscripts/iis-webdeploy.ps1) looks to be doing the same sort of thing and it's requiring multiple features. [This script as well](https://github.com/Azure/azure-quickstart-templates/blob/master/201-vmss-win-iis-app-ssl/dsc/serviceDSCVMSS.ps1). All I did was Google the GUID in the URL for the .msi file. – Bacon Bits Jan 03 '18 at 16:30
  • There is a bunch more in the script. i only showed the first. I am basically using the quick starter template https://github.com/Azure/azure-quickstart-templates/blob/master/201-vmss-win-iis-app-ssl/dsc/frontEndDSCVMSS.ps1 linked in the question also. You can see from the image that IIS is installed and version is 10. – MPavlak Jan 03 '18 at 16:48

1 Answers1

5

It seems the version of URL Rewrite used in the quick start templates does not work with 2016-Datacenter latest.

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

Using this version seems to work

## 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"
}
MPavlak
  • 2,133
  • 1
  • 23
  • 38