Author Posts

September 20, 2017 at 2:37 pm

Using Azure Automation DSC, trying to find a way to modularize my node blocks so I'm not duplicating a lot of prerequisite code for each node. Is there a way to do this? Any advice would be appreciated.

Simple example of what I am trying to do:

$BaseConfig = {
    cChocoInstaller installChoco
    {
        InstallDir = "c:\choco"
    }
}

Configuration Example
{
    Import-DscResource -ModuleName cChoco

    Node Test1
    {
        $BaseConfig

        # Install JDK8
        cChocoPackageInstaller installJdk8
        {
            Name = "jdk8"
            DependsOn = "[cChocoInstaller]installChoco"
        }
    }

    Node Test2
    {
        $BaseConfig

        # Install Chrome
        cChocoPackageInstaller installChrome
        {
            Name = "googlechrome"
            DependsOn = "[cChocoInstaller]installChoco"
        }
    }
}

September 20, 2017 at 11:20 pm

This is clearly a use case of Composite resources however according to the last documentation I saw Azure DSC Automation doesn't support it. But, I haven't tested it yet, I'm about to, just upload the composite as a module and upload the MOF instead of the .PS1 but I think that should work if straight Composite doesn't.

September 21, 2017 at 12:17 am

Just tested it, Composite resources work just fine; a good post about it: http://blogs.recneps.net/post/PowerShell-DSC-Composite-Resources
Basically, you create should create your base config like this:

Configuration BaseConfig
{
  Import-DscResource -ModuleName cChoco

  cChocoInstaller installChoco
  {
      InstallDir = "c:\choco"
  }
}

and you need to save it as .schema.ps1 (notice there's no Node section). Then create the required folder structure, I create a module called "MyBaseConfig" and a resource called "BaseConfig":

C:\Program Files\WindowsPowerShell\Modules\MyBaseConfig\MyBaseConfig.psd1
C:\Program Files\WindowsPowerShell\Modules\MyBaseConfig\DSCResources\BaseConfig\BaseConfig.psd1
C:\Program Files\WindowsPowerShell\Modules\MyBaseConfig\DSCResources\BaseConfig\BaseConfig.schema.psm1

Now just zip it and upload it as a module in Azure DSC Automation (as well a Choco in this case). Now, just create your config as:

Configuration Example
{
    Import-DscResource -ModuleName MyBaseConfig
    Import-DscResource -ModuleName cChoco

    Node Test1
    {
        BaseConfig Base1
        {
          
        }

        # Install JDK8
        cChocoPackageInstaller installJdk8
        {
            Name = "jdk8"
            DependsOn = "[BaseConfig]Base1"
        }
    }

    Node Test2
    {
        BaseConfig Base1
        {
          
        }

        # Install Chrome
        cChocoPackageInstaller installChrome
        {
            Name = "googlechrome"
            DependsOn = "[BaseConfig]Base1"
        }
    }
}

And that's it. Just tested it and it works fine regardless of the documentation

September 21, 2017 at 12:32 pm

This is exactly what I need. Thanks!