简体   繁体   中英

Unable to run Node and Script in Desired State Configuration

Background

I am provisioning a VM in Azure using an ARM template and created a Desired State Configuration .ps1 file that installs and configures IIS. So far so good.

I then added a Script block right next to the Node block.

Current set up:

Configuration Main
{
    Param ( [string] $nodeName )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

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

        #other WindowsFeatures
    }

    Script FormatDiskScript
    {
        SetScript =
        {
            #Powershell to format disks
        }
        TestScript = { return $false }
        GetScript = { }
    }
}

Inside my ARM template, I have added the DSC extension to my VM and specified the url where to get the zip file, script to run and function to invoke.

"properties": {
  "publisher": "Microsoft.Powershell",
  "type": "DSC",
  "typeHandlerVersion": "2.23",
  "autoUpgradeMinorVersion": true,
  "settings": {
    "configuration": {
      "url": "[concat(parameters('_artifactsLocation'), '/', variables('dscArchiveFolder'), '/', variables('webvm_dscZipFileName'))]",
      "script": "webvm-dsc.ps1",
      "function": "Main"
    },
    "configurationArguments": {
      "nodeName": "[variables('webvm_name')]"
    }
  },
  "protectedSettings": {
    "configurationUrlSasToken": "[parameters('_artifactsLocationSasToken')]"
  }
}

Question

It generates two .mof files and executes both the Node and Script sections however only the Node section completes successfully.

When I run with only the Script , that works, so the Script is valid. I just get the problem when running both of them.

This is what I see in the output in C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.23.0.0\\Status\\0.status

Settings handler status to 'transitioning' 
Updating execution status 
DSC configuration completed
No meta mof back up file exist to restore ...
Settings handler status to 'error' 

Answer

After trying different approaches, I finally stumbled across one that worked. I simply placed the Script inside the Node instead of it being a peer:

Configuration Main
{
    Param ( [string] $nodeName )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

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

        #other WindowsFeatures

        Script FormatDiskScript
        {
             SetScript =
             {
                 #Powershell to format disks
             }
             TestScript = { return $false }
             GetScript = { }
        }
    }
}

You need to create 2 configurations inside DSC configuration (say Main and Manual) and put the thing you want executed with ARM Template into main and the other thing into manual

Or create 2 separate configurations in 2 separate files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM