FATAL: SystemCallError: The parameter is incorrect. - ReportEvent

We keep getting this error at the end of our chef-client runs. It seems to be random, meaning it does not happen all the time on all the servers, just some of the time on some of the servers.

Error:
INFO: Running queued delayed notifications before re-raising exception
ERROR: Running exception handlers
ERROR: Exception handlers complete
FATAL: SystemCallError: The parameter is incorrect. - ReportEvent

We are running Chef on Server 2008 and 2012 client machines, and the recipe we are running is very simple, it just calls a .cmd file on the client, which calls a separate PowerShell script. Once the execution is complete we get this error.

Any ideas as to what is causing this error and how we can remedy it?

The good news is that this error does not seem to block the cookbooks/recipes from running.

There is powershell scripting directly within a chef recipe. You could try and call that directly rather than using a cmd/batch file.

  outfile = 'c:\outputpath\fileoutput.exe'
  url = "https://mydomain.com/myfile.exe"
  powershell_script 'download JDK' do
    code <<-EOH
    $WebClient = New-Object System.Net.WebClient
    $URL = "#{url}"
    $output = "#{outfile}"
    $WebClient.DownloadFile("$URL", "$OUTPUT")
    EOH
  end

Also, do you get ANY error’s when you run the powershell script independent of chef?

We use powershell_script in our recipes and get the same behavior as mentioned above, sometimes get the error and sometimes not. We also do not get errors when powershell scripts are run on the client server independent of Chef.

What execution policy for powershell scripts is on the remote machine? Get-ExecutionPolicy from powershell. For testing I always set this to unrestricted - Which yes, isn’t the best method, but I don’t have the luxury of a public facing CA!

Our servers are usually set to RemoteSigned. I also ran our cookbooks on a server that threw that error today but didn’t get the error this time. Weird.

Within the powershell_script code block set the below

$ErrorActionPreference = "Stop"

This will force the PowerShell to exit on error which will flow up to chef if there is an issue.

also you can try adding --log_level debug as part of your chef-client run and that hopefully will give you some better information

Thanks for the tip. I’ve added $ErrorActionPreference = "Stop" to our recipe to see if that will help.

Also, this is how we run the chef-client, and --log_level debug does not seem to be supported by knife winrm:

knife winrm <node> chef-client --manual-list --winrm-user <user> --winrm-password <password> --winrm-shell powershell

Is there another way to get debug log output?

You could use the Start-Transcript -Path 'c:\logfile.log' -Append (With the append to aggregate multiple run’s logging) to collect what the powershell script is doing? Don’t forget to add a Stop-Transcript in there and remove the $ErrorActionPreference = "Stop" so that the script continues as expected…

This is an on the fly simple way of doing logging.

the --log_level debug is on the chef-client so you should be able to do something like

knife winrm “chef-client --log_level debug” --manual-list --winrm-user --winrm-password --winrm-shell powershell

Thanks svucich and stonesbg for the excellent replies. We will try your suggestions.