Referencing composite resources

This topic contains 10 replies, has 3 voices, and was last updated by Profile photo of David Jones David Jones 2 years ago.

  • Author
    Posts
  • #20718
    Profile photo of Ryan Young
    Ryan Young
    Participant

    Okay so suppose I have a Composite resource that I create using Steves "new-dsccompositeresource" function. (this is what shows up in the WebServersDefaultWinAuth.schema.psm1 file)

    configuration WebServersDefaultWinAuth {
                     WindowsFeature IIS {
                        Ensure = 'Present'
                        Name = 'Web Server'
                    }
                    WindowsFeature aspnet45 {
                        Ensure = 'Present'
                        Name = 'Web-Asp-Net45'
                    }
                    WindowsFeature WebWindowsAuth {
                        Name = 'Web-Windows-Auth'
                        Ensure = 'Present'
        }
      
    }

    In my master config, when I go to reference it, I know I can reference this composite resource like so:

    Configuration WebServer {
        Node $AllNodes.Where{$_.NodeRole -eq "WebServer"}.NodeGUID {
            WebServersDefaultWinAuth aspnet45 {}
        }
    }

    Question: In the above if I interpret it right, I'm only taking the aspnet45 feature out of WebServersDefaultWinAuth. What would the formatting look like if I want more of them? What would the formatting look like if I wanted to use all features in WebServersDefaultWinAuth?

    Thanks again, as always! 🙂

  • #20722
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    You're always using the entire composite configuration. In this line:

    WebServersDefaultWinAuth aspnet45 {}
    

    The word "aspnet45" is just the name you're assigning to that composite resource. It could just as easily have been WebServersDefaultWinAuth GeorgeOfTheJungle {}

  • #20723
    Profile photo of Ryan Young
    Ryan Young
    Participant

    Oh okay I wasn't interpreting it correctly then! What if I wanted to pick and choose one of the things out of the composite resource then? I imagine said things would go in the braces at the end?

  • #20724
    Profile photo of Ryan Young
    Ryan Young
    Participant

    Another question / clarification. Steve's "new-dsccompositeresource" command has you editing RESOURCE.schema.psm1 files with you custom configs. In another powershell.org thread: https://powershell.org/forums/topic/how-are-people-managing-their-configuration/#post-20397

    David Jones seems to be referencing psd1 files? It's just confusing me a little. Or is it really just the mass size of his configuration that's just a little beyond me (for now!)

  • #20727
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    That other thread is talking about configuration data, not composite resources. (At least, the portions of it that refer to psd1 files.)

    As for your other question, you would have to add parameters to your composite resource, and then pass in values for those parameters in the configuration that's using it. For example:

    # Composite resource
    
    configuration MyCompositeResource
    {
        param (
            [bool] $IIS = $true,
            [bool] $XPSViewer = $true
        )
    
        if ($IIS)
        {
            WindowsFeature MyCompositeResource_IIS
            {
                Name = 'Web-Server'
                Ensure = 'Present'
            }
        }
        
        if ($IIS)
        {
            WindowsFeature MyCompositeResource_XPSViewer
            {
                Name = 'XPS-Viewer'
                Ensure = 'Present'
            }
        }
    }
    
    
    #####
    
    configuration MyConfig
    {
        Import-DscResource -ModuleName MyCompositeResourceModuleName
    
        node localhost
        {
            MyCompositeResource George
            {
                IIS = $true
                XPSViewer = $false
            }
        }
    }
    

    Personally, I think that's a little convoluted, and would not place resources into a composite resource if they were conditional like that.

  • #20728
    Profile photo of Ryan Young
    Ryan Young
    Participant

    Cool, very awesome. And while I'm at it (on a roll here lol). I imagine that if I wanted to reference multiple composite resources it'd look like this (as long as said resources don't conflict):

    Configuration CombinedWebServer {
        Node $AllNodes.Where{$_.NodeRole -eq "WebServer"}.NodeGUID {
            WebServersDefaultWinAuth aspnet45 {}
            SomeOtherModuleIWant    SomeFeatureINameAndConfigured {}
        }
    }
  • #20729
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Yep. You can have any number of resources inside a Node block (and those resources can be composite resources if you want; no limitations.) The only thing you have to be careful of is that there are no duplicated resource names or key properties in the entire configuration, including inside any composite resources. If that happens, you'll get errors when you try to compile the MOF.

  • #20731
    Profile photo of Ryan Young
    Ryan Young
    Participant

    For "big laughs" I went to a server we already have and basically used get-windowsfeature -isinstalled $true (paraphrasing this) to get me a list of all the windows features installed on that thing. I then plugged ALL of those features into a single composite resource. Thing is, (admittedly out of lazyness and lack of time) I haven't specified the "depends upon" for each feature. I kind of just assume it'll go through the list, install what it can, error out and then pick up where it left off on next attempt. I was just about to test this, but maybe you can save me the time XD :)?

    Edit: clarifying it, I'll use this to apply to a new test server I put out.

  • #20734
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    I'm not sure what you're asking. If your windows features have dependencies, then you will probably need to make sure you've called those out properly in the DSC configuration.

  • #20737
    Profile photo of Ryan Young
    Ryan Young
    Participant

    Does dsc stop everything on error or continue I guess is the better question? If I fail to specify a dependancy for a windows feature, does it move on and try to install the next thing in the list? presuming that I have all dependancies in the list of things to install (eventually) but I'm just not telling DSC what those dependancies are, what'll happen?

  • #20744
    Profile photo of David Jones
    David Jones
    Participant

    Any error causes it to stop processing.

You must be logged in to reply to this topic.