September 2, 2015 at 7:42 am #29224
I have a resource that requires the ActiveDirectory module. Previously I would just use a DSC WindowsFeature resource to ensure it was installed prior to the DSC resource that requires it runs.
Since upgrading to PSv5 Production Preview, when it tries to apply the configuration it errors with:
Importing module POSH_xADOrganizationalUnit failed with error – The script 'POSH_xADOrganizationalUnit.psm1' cannot be run because the following modules that are specified by the "#requires" statements of the script are missing: ActiveDirectory.
The dependencies are still there, so I'm assuming it is preloading all the modules before applying. Should this method still work with the dependencies or do I need to adjust my DSC resource to check for the module and install it itself if it doesn't exist? That would be fine if I should do that, but I have other DSC resources that require modules that are installed via installers (MSI) and use the same dependency to make sure it is installed before the resource that needs it runs.
Update: I did verify the generated MOF has the correct dependencies listed.
September 2, 2015 at 7:47 am #29226
Hmm, that is awkward. Perhaps it should be a best practice not to use the #requires statement this way in DSC resource modules, but rather to check for the dependencies at execution time (rather than at import time).
September 2, 2015 at 7:51 am #29227
We are, I feel, in an awkward middle place with module dependencies right now. We need Import-Module to have an -InstallIfNeeded switch that uses PowerShellGet to retrieve dependencies from an authorized repo more or less transparently. I'm less thrilled about #requires because it's module-wide, which is less granular than id love.
And you've found a definite tricky spot in DSC specifically, which is that – basically – everything needs to be in place or available on a pull server in order to work. You can't easily use a configuration to deploy a dependency of that configuration. I think we will see some evolution to support auto installations from a repo, but not yet.
Meantime, for me, the right approach has been to – as you suggest – deal with it myself in code.
September 2, 2015 at 4:18 pm #29264
I commented out the #requires statement and this allows it to work in the expected fashion with DSC dependencies. I like the idea of the pull server having a nuget server embedded so it can feed the dependencies that way.
You must be logged in to reply to this topic.