How to create mofs from Configuration File and Configuration Data File

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Aaron Stainback Aaron Stainback 7 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #34801
    Profile photo of Aaron Stainback
    Aaron Stainback
    Participant

    I have a configuration data file like data.psd1
    @{
    AllNodes = @(
    @{
    NodeName = "*"
    LogPath = "C:\Logs"
    },

    @{
    NodeName = "machine1";
    Roles = @( "SmtpRole", "WebRole" )
    },

    @{
    NodeName = "machine2";
    Roles = @( "SmtpRole" )
    }
    )
    }

    I have a configuration like FarmConfiguration.ps1

    Configuration FarmConfiguration {
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'MyCustomDsc'

    Node $AllNodes.NodeName
    {
    SimpleTcpIpConfiguration SimpleTcpIp
    {
    }
    }

    Node $AllNodes.Where{$_.Roles -contains "WebRole"}.NodeName
    {
    WebConfiguration Web
    {
    }
    }

    Node $AllNodes.Where{$_.Roles -contains "SmtpRole"}.NodeName
    {
    SmtpConfiguration Smtp
    {
    }
    }
    }

    I know if I add "FarmConfiguration-ConfigurationData ConfigurationData.psd1" to the bottom of my FarmConfiguration.ps1 file then everything works fine.

    But this is a big problem I don't want my FarmConfiguration to know about the data file at all, it's check into source control.

    I want to be able to creates MOFs based on various different data files how can I do this? Thanks.

    #34802
    Profile photo of James Vierra
    James Vierra
    Participant

    I, too, am curious about the best way to do this.

    #34819
    Profile photo of Christian Sandfeld
    Christian Sandfeld
    Participant

    Assuming you are in the same directory as where you files are placed

    # Dot-source the PowerShell script holding your configuration
    . .\FarmConfiguration.ps1
    
    # Then your FarmConfiguration "function" is available for you to run, pointing to a data file of your choice
    FarmConfiguration -ConfigurationData .\ConfigurationData.psd1
    
    #34841
    Profile photo of Aaron Stainback
    Aaron Stainback
    Participant

    This is the first thing I tried and it did not work, I got no output nothing when trying this.

    #34886
    Profile photo of Aaron Stainback
    Aaron Stainback
    Participant

    Okay I found out how to do what I'm asking.

    For all practical purposes FarmConfiguration is a private function inside of the .ps1 file. So I updated FarmConfiguration.ps1 to the following.

    param(
    [Parameter(Mandatory)]
    [string]$ConfigurationData
    )

    Configuration FarmConfiguration {
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'MyCustomDsc'

    Node $AllNodes.NodeName
    {
    SimpleTcpIpConfiguration SimpleTcpIp
    {
    }
    }

    Node $AllNodes.Where{$_.Roles -contains "WebRole"}.NodeName
    {
    WebConfiguration Web
    {
    }
    }

    Node $AllNodes.Where{$_.Roles -contains "SmtpRole"}.NodeName
    {
    SmtpConfiguration Smtp
    {
    }
    }
    }

    FarmConfiguration -ConfigurationData $ConfigurationData

    Now that I've done that I'm able to call it from a separate script like you suggest

    .\FarmConfiguration.ps1 -ConfigurationData data.psd1

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.