[SOLVED] Chef doesn't create Scheduled Task correctly on Windows node

Hello, I've been trying to learn Chef and been following modules on learn.chef.io

I got to the Run chef-client periodically module, and I:

Created a role with web.json
Pushed the role to the Chef Server (confirmed it is there with knife role show web)
Finally, when I try knife node run_list set node1-windows "role[web]", I get this:

================================================================================
Error executing action add on resource 'chef_client_scheduled_task[Chef Client]'

computer.domain.org
Mixlib::ShellOut::ShellCommandFailed

windows_task[chef-client] (c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb line 47) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '-2147467259'
---- Begin output of schtasks /CREATE /TN "chef-client" /F /SC "minute" /ST "11:03" /MO "5" /RU "SYSTEM" /RL "HIGHEST" /TR "cmd /c "C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 60" " ----
STDOUT:
STDERR: ERROR: Invalid argument/option - '-L'.
Type "SCHTASKS /CREATE /?" for usage.
---- End output of schtasks /CREATE /TN "chef-client" /F /SC "minute" /ST "11:03" /MO "5" /RU "SYSTEM" /RL "HIGHEST" /TR "cmd /c "C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 60" " ----
Ran schtasks /CREATE /TN "chef-client" /F /SC "minute" /ST "11:03" /MO "5" /RU "SYSTEM" /RL "HIGHEST" /TR "cmd /c "C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 60" " returned -2147467259

Chef is trying to run this:
schtasks /CREATE /TN "chef-client" /F /SC "minute" /ST "11:03" /MO "5" /RU "SYSTEM" /RL "HIGHEST" /TR "cmd /c "C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 60" "

However, the correct syntax is this:
schtasks /CREATE /TN "chef-client" /F /SC "minute" /ST "11:03" /MO "5" /RU "SYSTEM" /RL "HIGHEST" /TR "cmd /c "C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 60" "

My node is Windows Server 2012 R2 (with PS 5.1, and Chef-Client 13.7.16)
On the Chef Server, the cookbook Chef-Client is at version 9.0.2

Your help is greatly appreciated.

Fixed: 9.0.3 and 9.0.4 both contain fixes for issues with scheduled task and newer chef-client releases.

This issue came back. Im on Chef DK v2.5.3 and client 13.8.5

* windows_task[chef-client] action create[2018-03-30T10:03:58-04:00] INFO: Processing windows_task[chef-client] action create (c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb line 46)

[2018-03-30T10:03:58-04:00] INFO: Processing windows_task[chef-client] action create (c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb line 46)

================================================================================
Error executing action create on resource ‘windows_task[chef-client]’

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received ‘-2147467259’
---- Begin output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
STDOUT:
STDERR: ERROR: Invalid argument/option - ‘-L’.

Type “SCHTASKS /CREATE /?” for usage.
---- End output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
Ran schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " returned -2147467259

Resource Declaration:

In c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb

46: windows_task ‘chef-client’ do
47: run_level :highest
48: command “cmd /c “#{client_cmd}””
49:
50: user new_resource.user
51: password new_resource.password
52: frequency new_resource.frequency.to_sym
53: frequency_modifier new_resource.frequency_modifier
54: start_time new_resource.start_time || start_time
55: end
56: end

Compiled Resource:

Declared in c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb:46:in `block in class_from_file’

windows_task(“chef-client”) do
action [:create]
default_guard_interpreter :default
declared_type :windows_task
cookbook_name “chef-client”
run_level :highest
command "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300"”
user “SYSTEM”
password nil
frequency :minute
frequency_modifier 30
start_time “10:33”
task_name “chef-client”
end

System Info:

chef_version=13.8.5
platform=windows
platform_version=10.0.14393
ruby=ruby 2.4.3p205 (2017-12-14 revision 61247) [x64-mingw32]
program_name=C:/opscode/chef/bin/chef-client
executable=C:/opscode/chef/bin/chef-client

[2018-03-30T10:04:02-04:00] INFO: Running queued delayed notifications before re-raising exception
[2018-03-30T10:04:02-04:00] INFO: Running queued delayed notifications before re-raising exception

================================================================================
Error executing action add on resource ‘chef_client_scheduled_task[Chef Client]’

Mixlib::ShellOut::ShellCommandFailed

windows_task[chef-client] (c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb line 46) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘-2147467259’
---- Begin output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
STDOUT:
STDERR: ERROR: Invalid argument/option - ‘-L’.

Type “SCHTASKS /CREATE /?” for usage.
---- End output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
Ran schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " returned -2147467259

Resource Declaration:

In c:/chef/cache/cookbooks/chef-client/recipes/task.rb

37: chef_client_scheduled_task ‘Chef Client’ do
38: user node[‘chef_client’][‘task’][‘user’]
39: password node[‘chef_client’][‘task’][‘password’]
40: frequency node[‘chef_client’][‘task’][‘frequency’]
41: frequency_modifier lazy { node[‘chef_client’][‘task’][‘frequency_modifier’] }
42: start_time node[‘chef_client’][‘task’][‘start_time’]
43: splay node[‘chef_client’][‘splay’]
44: config_directory node[‘chef_client’][‘conf_dir’]
45: log_directory node[‘chef_client’][‘log_dir’]
46: chef_binary_path node[‘chef_client’][‘bin’]
47: daemon_options node[‘chef_client’][‘daemon_options’]
48: end

Compiled Resource:

Declared in c:/chef/cache/cookbooks/chef-client/recipes/task.rb:37:in `from_file’

chef_client_scheduled_task(“Chef Client”) do
action [:add]
default_guard_interpreter :default
declared_type :chef_client_scheduled_task
cookbook_name “chef-client”
recipe_name “task”
user “SYSTEM”
password nil
frequency “minute”
frequency_modifier 30
start_time nil
splay “300”
config_directory “C:/chef”
log_directory “C:/chef/log”
chef_binary_path “C:/opscode/chef/bin/chef-client”
daemon_options []
end

System Info:

chef_version=13.8.5
platform=windows
platform_version=10.0.14393
ruby=ruby 2.4.3p205 (2017-12-14 revision 61247) [x64-mingw32]
program_name=C:/opscode/chef/bin/chef-client
executable=C:/opscode/chef/bin/chef-client

[2018-03-30T10:04:03-04:00] INFO: Running queued delayed notifications before re-raising exception
[2018-03-30T10:04:03-04:00] INFO: Running queued delayed notifications before re-raising exception

Running handlers:
[2018-03-30T10:04:03-04:00] ERROR: Running exception handlers
[2018-03-30T10:04:03-04:00] ERROR: Running exception handlers

  • Chef::Handler::Datadog
    Running handlers complete
    [2018-03-30T10:04:03-04:00] ERROR: Exception handlers complete
    [2018-03-30T10:04:03-04:00] ERROR: Exception handlers complete
    Chef Client failed. 0 resources updated in 01 minutes 09 seconds
    [2018-03-30T10:04:03-04:00] INFO: Sending resource update report (run-id: e0de5e2c-b0b8-4a9a-9ebb-abb97118c160)
    [2018-03-30T10:04:03-04:00] INFO: Sending resource update report (run-id: e0de5e2c-b0b8-4a9a-9ebb-abb97118c160)
    [2018-03-30T10:04:04-04:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
    [2018-03-30T10:04:04-04:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
    [2018-03-30T10:04:04-04:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
    [2018-03-30T10:04:04-04:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
    [2018-03-30T10:04:04-04:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: chef_client_scheduled_task[Chef Client] (chef-client::task line 37) had an error: Mixlib::ShellOut::ShellCommandFailed: windows_task[chef-client] (c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb line 46) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘-2147467259’
    ---- Begin output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
    STDOUT:
    STDERR: ERROR: Invalid argument/option - ‘-L’.

Type “SCHTASKS /CREATE /?” for usage.
---- End output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
Ran schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " returned -2147467259
[2018-03-30T10:04:04-04:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: chef_client_scheduled_task[Chef Client] (chef-client::task line 37) had an error: Mixlib::ShellOut::ShellCommandFailed: windows_task[chef-client] (c:/chef/cache/cookbooks/chef-client/resources/scheduled_task.rb line 46) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘-2147467259’
---- Begin output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
STDOUT:
STDERR: ERROR: Invalid argument/option - ‘-L’.

Type “SCHTASKS /CREATE /?” for usage.
---- End output of schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " ----
Ran schtasks /CREATE /TN “chef-client” /F /SC “minute” /ST “10:33” /MO “30” /RU “SYSTEM” /RL “HIGHEST” /TR "cmd /c “C:/opscode/chef/bin/chef-client -L C:/chef/log/client.log -c C:/chef/client.rb -s 300” " returned -2147467259

As a followup, this error was caused by running a chef-client v13.8+ on the host with the chef-client cookbook at a version below 9.0.3/4.

Do we know "what" about the chef-client cookbook was causing this?