[PUP-3203] scheduled_task triggers cannot be updated Created: 2014/09/09  Updated: 2019/04/04  Resolved: 2014/10/13

Status: Closed
Project: Puppet
Component/s: Types and Providers
Affects Version/s: PUP 3.7.0, PUP 3.7.1
Fix Version/s: PUP 3.7.2

Type: Bug Priority: Normal
Reporter: Sam Weston Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: regression, scheduled_task, windows
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7 x64


Attachments: Text File trace.txt    
Issue Links:
Blocks
Relates
relates to PUP-1165 Spurious 'trigger changed' messages g... Closed
relates to PUP-3247 Win32::TaskScheduler#trigger_string d... Closed
Template:
Story Points: 1
Sprint: Platform 2014-10-15
QA Contact: Eric Thompson

 Description   

I'm using the scheduled_task provider to create a daily task. The initial task creation goes fine, but on any future puppet run I get things like this:

change from {'every' => '1', 'schedule' => 'daily', 'start_date' => '2014-9-9', 'start_time' => '12:00'} to [{'every' => '1', 'schedule' => 'daily', 'start_date' => '2014-9-8', 'start_time' => '12:00'}] failed: no implicit conversion from nil to integer

I previously had a less complicated definition and got this error:

change from {'every' => '1', 'schedule' => 'daily', 'start_date' => '2014-9-8', 'start_time' => '12:00'} to [{'schedule' => 'daily', 'start_time' => '12:00'}] failed: no implicit conversion from nil to integer

Unfortunately I'm not sure if this was present in 3.6.2 as all my machines are running 3.7.0 and set to automatically upgrade. I made this class shortly before the upgrade and I don't think it was a problem.

Am I the only one having this problem?



 Comments   
Comment by Sam Weston [ 2014/09/10 ]

I've downgraded my machine to 3.6.2 and am now pretty confident that this is a problem with 3.7.0 only.

Comment by Josh Cooper [ 2014/09/10 ]

Sam Weston can you post the scheduled_task resource from your manifest, also please run 3.7.0 agent as: puppet agent -td --trace and include the resulting stack trace.

Comment by Josh Cooper [ 2014/09/10 ]

This might be a duplicate of PUP-1165, though the "no implicit conversion from nil to integer" message is new

Comment by Sam Weston [ 2014/09/11 ]

I've attached the trace as requested. Here is what I've got in puppettest.pp:

 scheduled_task { 'Set _JAVA_OPTIONS':
    command => "C:\ProgramData\PuppetLabs\javaenv.bat",
    ensure  => present,
    trigger => {
      schedule   => daily,
      start_time => '12:00',
    }
  }

Comment by Josh Cooper [ 2014/09/15 ]

Thanks Sam Weston, The manifest above has a problem in that the `command` property uses double-quotes and single backslashes. This will cause puppet to interpret "\P", etc as escape sequences, leading to errors like:

Warning: Unrecognised escape sequence '\P' in file C:/Users/sweston/puppettest.pp at line 2
Warning: Unrecognised escape sequence '\P' in file C:/Users/sweston/puppettest.pp at line 2
Warning: Unrecognised escape sequence '\j' in file C:/Users/sweston/puppettest.pp at line 2

See https://docs.puppetlabs.com/puppet/3.7/reference/lang_windows_file_paths.html#using-backslashes-in-double-quoted-strings for more info. You'll want to either use single quotes and single backslashes, or double quotes and double backslashes.

That said, I was not able to reproduce the problem you're seeing. From the stack trace, it looks like puppet is trying to delete a trigger (by index) that doesn't exist.

Can you try running "Start Command Prompt with Puppet" as an Administrator, save the following script to tasks.rb, execute it as ruby tasks.rb, and attach the result?

require 'puppet'
require 'puppet/util/windows'
require 'puppet/util/windows/taskscheduler'
require 'pp'
require 'ffi'
 
# workaround https://tickets.puppetlabs.com/browse/PUP-3247
class Win32::TaskScheduler
  def trigger_string(index)
    raise Error.new('No current task scheduler. ITaskScheduler is NULL.') if @pITS.nil?
    raise Error.new('No currently active task. ITask is NULL.') if @pITask.nil?
    raise TypeError unless index.is_a?(Numeric)
 
    trigger = ""
 
    FFI::MemoryPointer.new(:pointer) do |ptr|
      @pITask.GetTriggerString(index, ptr)
 
      ptr.read_com_memory_pointer do |str_ptr|
        trigger = str_ptr.read_arbitrary_wide_string_up_to(256)
      end
    end
 
    trigger
  end
end
 
Win32::TaskScheduler.new.tasks.collect do |job_file|
  task = Win32::TaskScheduler.new
  task.activate(job_file)
 
  puts "Task        '#{job_file}'"
  puts "Command     '#{task.application_name}'"
  puts "Args        '#{task.parameters}'"
  puts "Working dir '#{task.working_directory}'"
  puts "User        '#{task.account_information}'"
 
  count = task.trigger_count
  puts "Triggers #{count}"
  task.trigger_count.times do |i|
    begin
      puts "trigger #{i}"
      pp task.trigger(i)
    rescue => detail
      puts "Failed to load trigger '#{task.trigger_string(i)}'"
    end
  end
end

Comment by Sam Weston [ 2014/09/16 ]

Hi Josh. Thanks for the heads up about the windows paths.

Here is the output from that command:

Task        'Adobe Flash Player Updater.job'
Command     'C:\Windows\SysWOW64\Macromed\Flash\FlashPlayerUpdateService.exe'
Args        ''
Working dir ''
User        ''
Triggers 1
trigger 0
{"start_year"=>2000,
 "start_month"=>1,
 "start_day"=>1,
 "end_year"=>0,
 "end_month"=>0,
 "end_day"=>0,
 "start_hour"=>0,
 "start_minute"=>58,
 "minutes_duration"=>1440,
 "minutes_interval"=>60,
 "flags"=>0,
 "trigger_type"=>:TASK_TIME_TRIGGER_DAILY,
 "random_minutes_interval"=>0,
 "type"=>{"days_interval"=>1}}
Task        'G2MUpdateTask-S-1-5-21-3845744863-2409227386-3211111987-5638.job'
Command     'C:\Users\sweston\AppData\Local\Citrix\GoToMeeting\1558\g2mupdate.ex
e'
Args        ''
Working dir 'C:\Users\sweston\AppData\Local\Citrix\GoToMeeting\1558'
User        'SMALLBUSINESS\sweston'
Triggers 1
trigger 0
{"start_year"=>2014,
 "start_month"=>8,
 "start_day"=>26,
 "end_year"=>0,
 "end_month"=>0,
 "end_day"=>0,
 "start_hour"=>13,
 "start_minute"=>29,
 "minutes_duration"=>1439,
 "minutes_interval"=>60,
 "flags"=>0,
 "trigger_type"=>:TASK_TIME_TRIGGER_DAILY,
 "random_minutes_interval"=>0,
 "type"=>{"days_interval"=>1}}
Task        'GoogleUpdateTaskMachineCore.job'
Command     'C:\Program Files (x86)\Google\Update\GoogleUpdate.exe'
Args        '/c'
Working dir ''
User        ''
Triggers 2
trigger 0
Failed to load trigger 'Run at user logon'
trigger 1
{"start_year"=>2014,
 "start_month"=>9,
 "start_day"=>10,
 "end_year"=>0,
 "end_month"=>0,
 "end_day"=>0,
 "start_hour"=>14,
 "start_minute"=>25,
 "minutes_duration"=>0,
 "minutes_interval"=>0,
 "flags"=>0,
 "trigger_type"=>:TASK_TIME_TRIGGER_DAILY,
 "random_minutes_interval"=>0,
 "type"=>{"days_interval"=>1}}
Task        'GoogleUpdateTaskMachineUA.job'
Command     'C:\Program Files (x86)\Google\Update\GoogleUpdate.exe'
Args        '/ua /installsource scheduler'
Working dir ''
User        ''
Triggers 1
trigger 0
{"start_year"=>2014,
 "start_month"=>9,
 "start_day"=>10,
 "end_year"=>0,
 "end_month"=>0,
 "end_day"=>0,
 "start_hour"=>14,
 "start_minute"=>25,
 "minutes_duration"=>1440,
 "minutes_interval"=>60,
 "flags"=>0,
 "trigger_type"=>:TASK_TIME_TRIGGER_DAILY,
 "random_minutes_interval"=>0,
 "type"=>{"days_interval"=>1}}
Task        'GoogleUpdateTaskUserS-1-5-21-3845744863-2409227386-3211111987-5638C
ore.job'
Command     'C:\Users\sweston\AppData\Local\Google\Update\GoogleUpdate.exe'
Args        '/c'
Working dir ''
User        'SMALLBUSINESS\sweston'
Triggers 1
trigger 0
{"start_year"=>2014,
 "start_month"=>6,
 "start_day"=>17,
 "end_year"=>0,
 "end_month"=>0,
 "end_day"=>0,
 "start_hour"=>16,
 "start_minute"=>14,
 "minutes_duration"=>0,
 "minutes_interval"=>0,
 "flags"=>0,
 "trigger_type"=>:TASK_TIME_TRIGGER_DAILY,
 "random_minutes_interval"=>0,
 "type"=>{"days_interval"=>1}}
Task        'GoogleUpdateTaskUserS-1-5-21-3845744863-2409227386-3211111987-5638U
A.job'
Command     'C:\Users\sweston\AppData\Local\Google\Update\GoogleUpdate.exe'
Args        '/ua /installsource scheduler'
Working dir ''
User        'SMALLBUSINESS\sweston'
Triggers 1
trigger 0
{"start_year"=>2014,
 "start_month"=>6,
 "start_day"=>17,
 "end_year"=>0,
 "end_month"=>0,
 "end_day"=>0,
 "start_hour"=>16,
 "start_minute"=>14,
 "minutes_duration"=>1440,
 "minutes_interval"=>60,
 "flags"=>0,
 "trigger_type"=>:TASK_TIME_TRIGGER_DAILY,
 "random_minutes_interval"=>0,
 "type"=>{"days_interval"=>1}}
Task        'Set _JAVA_OPTIONS.job'
Command     'C:\ProgramData\PuppetLabs\javaenv.bat'
Args        ''
Working dir ''
User        ''
Triggers 1
trigger 0
{"start_year"=>2014,
 "start_month"=>9,
 "start_day"=>10,
 "end_year"=>0,
 "end_month"=>0,
 "end_day"=>0,
 "start_hour"=>12,
 "start_minute"=>0,
 "minutes_duration"=>0,
 "minutes_interval"=>0,
 "flags"=>0,
 "trigger_type"=>:TASK_TIME_TRIGGER_DAILY,
 "random_minutes_interval"=>0,
 "type"=>{"days_interval"=>1}}

Comment by Kylo Ginsberg [ 2014/09/29 ]

Untagging for 3.7.2 and assigning to Josh Cooper who had context.

Comment by Josh Cooper [ 2014/10/02 ]

I was able to reproduce... somehow

Error: no implicit conversion from nil to integer
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util/windows/com.rb:141:in `call'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util/windows/com.rb:141:in `block (3 levels) in []'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util/windows/taskscheduler.rb:585:in `delete_trigger'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb:186:in `block in trigger='
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb:185:in `reverse_each'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb:185:in `trigger='
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/property.rb:178:in `call_provider'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/property.rb:503:in `set'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/property.rb:581:in `sync'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction/resource_harness.rb:204:in `sync'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction/resource_harness.rb:128:in `sync_if_needed'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction/resource_harness.rb:89:in `block in perform_changes'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction/resource_harness.rb:88:in `each'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction/resource_harness.rb:88:in `perform_changes'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction/resource_harness.rb:20:in `evaluate'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction.rb:204:in `apply'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction.rb:217:in `eval_resource'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction.rb:147:in `call'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction.rb:147:in `block (2 levels) in evaluate'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util.rb:327:in `block in thinmark'
C:/Program Files/Puppet Labs/Puppet Enterprise/sys/ruby/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util.rb:326:in `thinmark'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction.rb:147:in `block in evaluate'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/graph/relationship_graph.rb:118:in `traverse'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction.rb:138:in `evaluate'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/resource/catalog.rb:169:in `block in apply'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util/log.rb:149:in `with_destination'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/transaction/report.rb:112:in `as_logging_destination'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/resource/catalog.rb:168:in `apply'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/configurer.rb:118:in `block in apply_catalog'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util.rb:161:in `block in benchmark'
C:/Program Files/Puppet Labs/Puppet Enterprise/sys/ruby/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util.rb:160:in `benchmark'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/configurer.rb:117:in `apply_catalog'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/configurer.rb:222:in `run_internal'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/configurer.rb:132:in `block in run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/context.rb:64:in `override'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet.rb:244:in `override'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/configurer.rb:131:in `run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent.rb:47:in `block (4 levels) in run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent/locker.rb:20:in `lock'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent.rb:47:in `block (3 levels) in run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent.rb:117:in `with_client'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent.rb:44:in `block (2 levels) in run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent.rb:82:in `run_in_fork'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent.rb:43:in `block in run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application.rb:179:in `call'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application.rb:179:in `controlled_run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/agent.rb:41:in `run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application/agent.rb:356:in `onetime'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application/agent.rb:322:in `run_command'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application.rb:384:in `block (2 levels) in run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application.rb:510:in `plugin_hook'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application.rb:384:in `block in run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util.rb:488:in `exit_on_fail'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/application.rb:384:in `run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util/command_line.rb:146:in `run'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/lib/puppet/util/command_line.rb:92:in `execute'
C:/Program Files/Puppet Labs/Puppet Enterprise/puppet/bin/puppet:8:in `<main>'
Error: /Stage[main]/Pe_mcollective::Server/Scheduled_task[pe-mcollective-metadata]/trigger: change from {'every' => '1', 'schedule' => 'daily', 'start_date' => '2014-9-19', 'start_time' => '13:00'} to [{'every' => '1', 'schedule' => 'daily', 'start_time' => '13:00'}] failed: no implicit conversion from nil to integer

Comment by Josh Cooper [ 2014/10/02 ]

This has the same root cause as described in https://tickets.puppetlabs.com/browse/PUP-1165?focusedCommentId=102949&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-102949. The current trigger has a start_date while the desired trigger does not. Puppet incorrectly thinks the current trigger needs to be deleted, and along the way has lost the index for that trigger. So then it tries to delete the trigger with index nil.

Comment by Rob Reynolds [ 2014/10/09 ]

Merged into stable at 69a35f21 and up to master at fcc76ccd5c

Comment by Eric Thompson [ 2014/10/13 ]

verified in win2012r2-ruby64 at stable SHA a327be7 with

# use Josh's manifest as above
# change start_time
# run again:
Notice: Compiled catalog for bw72vphos85hyye.delivery.puppetlabs.net in environment production in 0.14 seconds
Notice: /Stage[main]/Main/Scheduled_task[spurious_task]/trigger: trigger changed '[{'enabled' => 'true', 'every' => '1', 'index' => '0', 'schedule' => 'daily', 'start_date' => '2014-10-13', 'start_time' => '15:00'}]' to '[{'every' => '1', 'schedule' => 'daily', 'start_time' => '16:20'}]'
Notice: Finished catalog run in 0.03 seconds
# run again:
$ cmd.exe /c puppet apply manifest.pp
Notice: Compiled catalog for bw72vphos85hyye.delivery.puppetlabs.net in environment production in 0.14 seconds
Notice: Finished catalog run in 0.03 seconds

Comment by Karthik Durairajan [ 2017/03/09 ]

Hi,

We are trialing out Puppet Enterprise (V2016.1.1) and despite being mentioned in the Puppet documentation (https://docs.puppet.com/puppet/4.9/ty...), it looks like the below scheduled_task trigger options don't work.

minutesinterval minutesduration

Puppet agent run fails with the error as seen below. Any advise on this would be great:

Error: Failed to apply catalog: Parameter trigger failed on Scheduledtask[SQL Backup Monitor]: Unknown trigger option(s): ['minutesduration', 'minutesinterva l'] at /etc/puppetlabs/code/environments/production/modules/sqlbackupscheduler/ manifests/init.pp:6 Wrapped exception: Unknown trigger option(s): ['minutesduration', 'minutesinterval']

Thanks, Karthik

Comment by Josh Cooper [ 2017/05/21 ]

Hi Karthik Durairajan you're issue looks different from this closed one. Note the options have an underscore, so that should be minutes_duration and minutes_interval. If you still have issues, please file a new ticket, and include the output from puppet agent -td --trace.

Generated at Mon Sep 23 06:02:33 PDT 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.