Code Monkey home page Code Monkey logo

Comments (11)

BladeFireLight avatar BladeFireLight commented on August 12, 2024

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.

from dsc.

dlwyatt avatar dlwyatt commented on August 12, 2024

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.

from dsc.

BladeFireLight avatar BladeFireLight commented on August 12, 2024

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.

from dsc.

dlwyatt avatar dlwyatt commented on August 12, 2024

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.

from dsc.

BladeFireLight avatar BladeFireLight commented on August 12, 2024

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'
}

from dsc.

BladeFireLight avatar BladeFireLight commented on August 12, 2024

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.

from dsc.

smurawski avatar smurawski commented on August 12, 2024

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?

from dsc.

dlwyatt avatar dlwyatt commented on August 12, 2024

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?

from dsc.

BladeFireLight avatar BladeFireLight commented on August 12, 2024

$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

from dsc.

BladeFireLight avatar BladeFireLight commented on August 12, 2024

think I may have it.

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

from dsc.

BladeFireLight avatar BladeFireLight commented on August 12, 2024

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

from dsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.