Search code examples
powershellazuredsc

Configure Azure VM LCM before running DSC Configuration via ARM template


I'm trying to configure an Azure VM via an ARM template and need to set the Local Configuration Manager on the VM to allow reboots prior to running the DSC configuration. I have a method that works at times but not always. I'm running the following script via the Azure CustomScriptExtension

[DscLocalConfigurationManager()]
Configuration ConfigureLcm {
  Node localhost {
    Settings {
        RebootNodeIfNeeded   = $true
    }
  }
}

if (!(Get-DscLocalConfigurationManager).RebootNodeIfNeeded) {
    ConfigureLcm -OutputPath C:\Config
    Set-DscLocalConfigurationManager -Path C:\Config
}

then the DSC extension. It seems like the CustomScriptExtension works but then the DSC extension changes RebootNodeIfNeeded back to false, maybe. The DSC extension depends on the CustomScriptExtension.

{
  "type": "extensions",
  "name": "DSC",
  "apiVersion": "2015-06-15",
  "location": "[resourceGroup().location]",
  "dependsOn": [
    "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]",
    "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'),  '/extensions/configlcm')]"

Has any one else experienced this?


Solution

  • The DSC Extension will overwrite the Local Configuration Manager (LCM), if you do not have explicit settings for the LCM they will revert to the default. Therefore you need to set it again in the Configuration Function you are using for your DSC Extension:

    Configuration Main
    {
      Node localhost
      {
        LocalConfigurationManager
        {
          RebootNodeIfNeeded = $true
          ...
        }
        # Your other resources
        ...
      }
    }´