Skip to content

bheuvel/testrepo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

dsc_script does not (allways) detect missing WhatIf correctly

Issue 2190; 'Try to apply dsc configuration even if what-if fails', will run dsc_script regardless off success or failure of running WhatIf, so will effectively "solve" this as well, but provide a wrong log message;

If using (e.g.) xRemoteDesktopAdmin or xWinEventLog, due to the missing WhatIf support, the following will be generated:

PowerShell provider xRemoteDesktopAdmin  failed to execute Set-TargetResource functionality with error message: A param

eter cannot be found that matches parameter name 'Whatif'.

    + CategoryInfo          : InvalidOperation: (:) [], CimException

    + FullyQualifiedErrorId : ProviderOperationExecutionFailure

    + PSComputerName        : .

(Note the linebreak in the middle of parameter)

This exception is evaluated using:

if what_if_exception_output.gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i

(local_configuration_manager.rb)

Unfortunately, the regex /\s+/,' ' converts the linebreak into a space, (debug output) results in:

ERROR: DSC operation failed: Powershell Cmdlet failed: PowerShell provider xRemoteDesktopAdmin failed to execute Set-TargetResource functionality with error message: A param eter cannot be found that matches parameter name 'Whatif'. + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : . The SendConfigurationApply function did not succeed. + CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException + FullyQualifiedErrorId : MI RESULT 1 + PSComputerName : . 

(NOTE the param eter)

Therefore the match is not made due to the difference generated by the gsub:

Part of exception output:

A parameter cannot be found that matches parameter name 'Whatif'

Regex that tries to match the/this WhatIf exception:

A param eter cannot be found that matches parameter name 'Whatif'

Solution: In general it makes sense to convert all tabs and potential doublespaces to single space to be able to match against a simple literal string. Converting linebreaks to a single space does provide better human readable text, but that is assuming a linebreak is not down in the middle of a word.

So either of the following will solve this specific scenario:

  • if what_if_exception_output.gsub(/\s+/ , '') =~ /Aparametercannotbefoundthatmatchesparametername'Whatif'/i
  • if what_if_exception_output.gsub(/[\r\n]+/, '') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i
  • if what_if_exception_output.gsub(/[\r\n]+/, '').gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i

I would propose the last (Created a pull request).

After that line of code, some Chef::Log::warn are executed using the /\s+/ regex. For improved readability I would propose to NOT change those.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages