Skip to content
This repository has been archived by the owner on May 15, 2018. It is now read-only.

Modules in DSC_Resorces cant be used to manage machine running invoke-DSCBuild. #107

Closed
BladeFireLight opened this issue Feb 17, 2015 · 11 comments

Comments

@BladeFireLight
Copy link

when I try to update my tools and it brakes I alwase fall back to a clean seutp and the sample build.

when it Trys to run I get some errors I think is related to the recent change of folders, having the resorces in both the DSC_Resorce folder and C:\Program Files\WindowsPowerShell\Modules (required for ISE to validate SampleConfiguration)

VERBOSE: Performing the operation "Test-DscResourceIsValid" on target "modules from H:\DSC\DSC_Tooling\Examples
DSC_Resources".
ImportCimAndScriptKeywordsFromModule : A second CIM class definition for 'PSHOrg_cSmbShare' was found while
processing the schema file 'C:\Program
Files\WindowsPowerShell\Modules\cSmbShare\DSCResources\PSHOrg_cSmbShare\PSHOrg_cSmbShare.Schema.mof'. This
class was already defined in the file 'H:\DSC\DSC_Tooling\Examples\DSC_Resources\cSmbShare\DSCResources\PSHOrg_
cSmbShare\PSHOrg_cSmbShare.Schema.mof'. Remove the redundant definition, and then try again.
At C:\windows\system32\windowspowershell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.p
sm1:2426 char:29

  •                 $null = ImportCimAndScriptKeywordsFromModule -Module $mod -R ...
    
  • - CategoryInfo          : NotSpecified: (:) [Write-Error], PSInvalidOperationException
    - FullyQualifiedErrorId : System.Management.Automation.PSInvalidOperationException,ImportCimAndScriptKeywo 
      rdsFromModule
      .... 
    
@BladeFireLight
Copy link
Author

it seems to be that line 11 of Test-DscResourceIsValid.ps1 is the point of failure
$AllResources = Get-DscResource | Where-Object {$_.ImplementedAs -like 'PowerShell'}
This is due to the path containing both SourceResourceDirectory and the Program Files location.

changeing the line to
$AllResources = Get-DscResource -ErrorAction SilentlyContinue | Where-Object {$_.ImplementedAs -like 'PowerShell'}
gets passed the error but it still fails to create the .mof files.

@dlwyatt
Copy link
Member

dlwyatt commented Feb 18, 2015

Hmm... the way I was using this in testing was to clear out everything in the PSModulePath that wasn't needed prior to running Invoke-DscBuild. Something like this:

$dependenciesDirectory = Join-Path $PSScriptRoot Dependencies

$env:PSModulePath = "$dependenciesDirectory;$pshome\Modules"

Invoke-DscBuild # etc

It looks like maybe we should make this a parameter to Invoke-DscBuild instead. It would automatically include $pshome\Modules and the DSC_Resources directories on the path when running the build, and you could optionally pass in other paths to Invoke-DscBuild as well (where you have things like Pester, cDscResourceDesigner, etc.) That way you don't run into this problem if the build server happens to have duplicate modules on its normal module path.

@BladeFireLight BladeFireLight changed the title Problems running Sample with current Devl branch Modules in DSC_Resorces cant be used to manage machine running invoke-DSCBuild. Feb 18, 2015
@BladeFireLight
Copy link
Author

Both Resource build and Configuration build will fail if any resource is both in program files and dsc_Resources.

while Resource build gives useful errors, Configuration does not.

I also found one of my resources was faulty and was braking configuration build, removing it solved it so now I can build scripts but only if I have my build.ps1 compare dsc_Resources to Program Files and removes resources, then puts them back at the end. This is not a good fix but it's got me working with the latest version.

@dlwyatt
Copy link
Member

dlwyatt commented Feb 19, 2015

I've just pushed a change to the Development branch to try to address this. Here's the new behavior:

  • By default, Invoke-DscBuild will now set the PSModulePath during its run so that only the $SourceResourceDirectory and $pshome\Modules folders are on the path.
  • There's a new parameter to Invoke-DscBuild called -ModulePath, which takes an optional array of strings for additional folders that should be on the module path. You might need to set this to make Invoke-DscBuild load $ConfigurationModuleName, for example.

The idea here is that everything DscBuild needs in order to do its job should be located somewhere other than the default PSModulePath on the build server. This way, it can run a build and test new versions of these modules without affecting the production state of the build server (which may also be managed by DSC.)

Let me know if this makes sense, and if it helps with the problems you were having.

@BladeFireLight
Copy link
Author

Thank you, that worked. I had to add the configuration location, in this case dsc_tooling
so my settings look like this

$BaseSettings = @{
WorkingDirectory = (Get-TempDirectory).FullName
SourceResourceDirectory = "$PSScriptRoot\DSC_Resources"
SourceToolDirectory = "$PSScriptRoot\DSC_Tooling"
DestinationRootDirectory = "$outBasePath\DSC_Out"
DestinationToolDirectory = "$outBasePath\DSC_Tools"
ModulePath = "$PSScriptRoot\DSC_Tooling"
ExcludedModules = 'Example', 'MyConfig', 'SampleConfiguration'
ConfigurationModuleName = 'MyConfig'
}

@BladeFireLight
Copy link
Author

This is not my day, it initially worked when I just updated the one file. but I thin copied all the Tools back into the module folder just to make sure my poking around was reversed, and now it's broken.
And when it fails to load the configuration it does not give any useful errors.

I'm going to try to pinpoint the failure to see if it's my config script or Invoke-DscConfiguration.

@smurawski
Copy link
Contributor

You may be hitting a bug with caching of resources. Is the LCM in debug mode? Or have you killed the wmi process hosting the lcm?

@dlwyatt
Copy link
Member

dlwyatt commented Feb 19, 2015

I haven't been using the DSC_Tooling functionality of DscBuild at all yet (and am not really sure what the use case is, there). Do you think $SourceToolDirectory should also be on the default module path when Invoke-DscBuild is running?

@BladeFireLight
Copy link
Author

$BaseSettings = @{
WorkingDirectory = (Get-TempDirectory).FullName
SourceResourceDirectory = "$PSScriptRoot\DSC_Resources"
SourceToolDirectory = "$PSScriptRoot\DSC_Tooling"
DestinationRootDirectory = "$outBasePath\DSC_Out"
DestinationToolDirectory = "$outBasePath\DSC_Tools"
ModulePath = "$PSScriptRoot\DSC_ConfigScript"
ExcludedModules = 'Example', 'MySConfig', 'SampleConfiguration'
ConfigurationModuleName = 'SampleConfiguration'
}

$TestInvokeConfig = @{
ConfigurationName = 'SampleConfiguration'
Configuration = $true
Resource = $flase
Tools = $false
}
Invoke-DscBuild @BaseSettings @TestInvokeConfig -ConfigurationData (Get-DscConfigurationData -Path "H:\DSC\DSC_Tooling\Examples\DSC_Configuration" -Force -Verbose) -Verbose

...
VERBOSE: Is a Configuration Build - True
VERBOSE:
VERBOSE: Performing the operation "Invoke-DscConfiguration" on target "Configuration module SampleConfiguration and co
nfiguration SampleConfiguration".
VERBOSE:
VERBOSE: Importing configuration module: SampleConfiguration
VERBOSE: Loading module from path 'H:\DSC\DSC_ConfigScript\SampleConfiguration\SampleConfiguration.psm1'.
VERBOSE: Loading module from path 'H:\DSC\DSC_ConfigScript\SampleConfiguration\SampleConfiguration.psm1'.
WARNING: Failed to load configuration module
WARNING:
Failed to load SampleConfiguration
At C:\Program Files\WindowsPowerShell\Modules\dscbuild\Invoke-DscConfiguration.ps1:35 char:21

  •                 throw "Failed to load $($script:DscBuildParameters.Configura ...
    
  •                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: (Failed to load SampleConfiguration:String) [], RuntimeException
    • FullyQualifiedErrorId : Failed to load SampleConfiguration

PS H:> $pathold = $env:PSModulePath
$env:PSModulePath = 'H:\DSC\DSC_Resources;C:\Windows\System32\WindowsPowerShell\v1.0\Modules;H:\DSC\DSC_ConfigScript'

PS H:> Import-Module -Name SampleConfiguration -Verbose
VERBOSE: Loading module from path 'H:\DSC\DSC_ConfigScript\SampleConfiguration\SampleConfiguration.psm1'.
Import-Module : The specified module 'DscConfiguration' was not loaded because no valid module file was found in any
module directory.
At H:\DSC\DSC_ConfigScript\SampleConfiguration\SampleConfiguration.psm1:2 char:1

  • Import-Module DscConfiguration -ErrorAction Stop
  • - CategoryInfo          : ResourceUnavailable: (DscConfiguration:String) [Import-Module], FileNotFoundException
    - FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
    

Import-Module : The specified module 'SampleConfiguration' was not loaded because no valid module file was found in
any module directory.
At line:1 char:1

  • Import-Module -Name SampleConfiguration -Verbose
  • - CategoryInfo          : ResourceUnavailable: (SampleConfiguration:String) [Import-Module], FileNotFoundExcepti 
      on
    - FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
    

PS H:> $env:PSModulePath = $pathold

@BladeFireLight
Copy link
Author

think I may have it.

ModulePath               = "$PSScriptRoot\DSC_ConfigScript", "$PSScriptRoot\DSC_Tooling"

@BladeFireLight
Copy link
Author

Looks like i'm good. all my configurations build, and I got all my configs and updated tools checked into the onprem git.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants