[PUP-3768] scheduled_task keeps reapplying Created: 2014/12/15  Updated: 2016/10/19  Resolved: 2016/06/24

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

Type: Bug Priority: Normal
Reporter: zack shahan Assignee: Erick Banks
Resolution: Fixed Votes: 0
Labels: customer-escalation, scheduled_task, windows
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
relates to PUP-1498 scheduled_task won't update command Closed
Acceptance Criteria:

Scheduled_task should not re-apply for arguments of string len up to 4096 chars, and commands of string len up to 260 chars.

The acceptance test: acceptance/tests/resource/scheduled_task/should_modify.rb
should pass.

The integration test: spec/integration/util/windows/taskscheduler_spec.rb
should pass.

Story Points: 2
Sprint: Windows 2016-06-15, Windows 2016-06-29


Every puppet run I have a scheduled task that gets re-applied even though there was no change. After doing some digging, it looks like it applies correctly, but on the next run, it is only comparing a part of the argument string instead of the full string.

It looks like when doing the comparison, it is only reading in the first 256 characters instead of the entire string.

scheduled_task { 'cloud_backup':
ensure => present,
command => 'C:\Program Files\Duplicati\Duplicati.CommandLine.exe',
arguments => template('fdlic/duplicati/backup.erb'),
trigger =>

{ schedule => weekly, start_time => '08:00:00', start_date => '2014-05-08' }


arguments changed 'backup --ftp-username=empty --ftp-password=empty --max-upload-pr-second=500kb --thread-priority=BelowNormal --use-ssl --passphrase=empty --aes-encryption-dont-allow-fallback=true --full-if-older-than=1M --exclude=.wma --exclude=.mp3 --exclu' to 'backup --ftp-username=empty --ftp-password=empty --max-upload-pr-second=500kb --thread-priority=BelowNormal --use-ssl --passphrase=empty --aes-encryption-dont-allow-fallback=true --full-if-older-than=1M --exclude=.wma --exclude=.mp3 --exclude=.acc' --exclude=.mp4 --exclude=.avi --exclude=.3gp --exclude=.mpg --exclude=.mov

Comment by Josh Cooper [ 2014/12/15 ]

The windows APIs for retrieving task command, parameters, etc don't tell you how long the string is, instead you have to keep reading until you run into a wide null terminator. We enforce a maximum length of 256 to ensure we don't read off the end of the string: https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/windows/taskscheduler.rb#L408. Looks like 256 is not large enough for scheduled task parameters. We should check the other task methods as well, e.g. working directory, trigger string, comment, creator, account info.

Comment by Glenn Sarti [ 2016/05/25 ]

Additional issue has been reported;

From the Windows Slack Channel (User: jesusv)


scheduled_task { 'PUPPET-ReiniciaServidor-100':
        ensure => present,
        enabled => true,
        command => 'C:\ScriptsPuppet\Utilidades\Reinicia_Servidor\Reinicia_Servidor.bat',
        user => $usuario,
        password => $contrasena,
        trigger   => {
            schedule => daily,
            every => 1,
            start_date => '2016-01-01',
            start_time => '05:00',
        require => File['C:/ScriptsPuppet/Utilidades/Reinicia_Servidor'],

Puppet output

1st run. Task created Ok
Running Puppet agent on demand ...
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for win-i8nmrvu57c7
Info: Applying configuration version '1464186265'
Notice: /Stage[main]/tarea_win_reinicia_servidor/Scheduled_task[PUPPET-ReiniciaServidor-100]/ensure: created
Notice: Applied catalog in 7.64 seconds
Presione una tecla para continuar . . .
2nd run. Detect changes but doesn't update scheduled task
Running Puppet agent on demand ...
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for win-i8nmrvu57c7
Info: Applying configuration version '1464186340'
Notice: /Stage[main]/tarea_win_reinicia_servidor/Scheduled_task[PUPPET-ReiniciaServidor-100]/command: command changed 'C:\Sc
riptsPuppet\Utilidades\Reinicia_Servidor\Reinicia_Servidor.bat' to 'C:\ScriptsPuppet\Utilidades\Reinicia_Servidor\Reinicia_Servidor_
Notice: /Stage[main]/tarea_win_reinicia_servidor/Scheduled_task[PUPPET-ReiniciaServidor-100]/trigger: trigger changed '[{'en
abled' => 'true', 'every' => '1', 'index' => '0', 'minutes_duration' => '0', 'minutes_interval' => '0', 'schedule' => 'daily', 'star
t_date' => '2016-1-1', 'start_time' => '05:00'}]' to '[{'every' => '1', 'schedule' => 'daily', 'start_date' => '2016-01-01', 'start_
time' => '08:00'}]'

Comment by Ethan Brown [ 2016/06/09 ]

Some minor things to take care of in the PR - comments left there

Comment by Glenn Sarti [ 2016/06/20 ]

PR 5035 Review

Unit tests ok
Integration tests ok
Using test manifests, can prove the old code fails and this PR fixes the issue with argument and command length

Comment by Glenn Sarti [ 2016/06/20 ]

PR 5035 merged into stable at;

Comment by Glenn Sarti [ 2016/06/21 ]

Build was successful


Comment by Glenn Sarti [ 2016/06/21 ]

Merged into master at;

Comment by Erick Banks [ 2016/06/24 ]

QA demo'ed to me by Glenn. I pulled the puppet.msi from http://nightlies.puppetlabs.com/puppet-agent/latest/repos/windows/ and ensured the changes from the pr above were included. Then ran a puppet apply on a manifest with "arguments=>x" where "x" was a string of characters 300 long.

Also I feel the acceptance tests are sufficient to prove the change now accepts long argument strings. Will not do FR.

Comment by Jesus Vila [ 2016/06/29 ]

Downloaded last msi from http://nightlies.puppetlabs.com/puppet-agent/latest/repos/windows/ too. Test with my manifests and runs ok. Thank you very much.

Running on server
ii puppet-agent 1.5.2-1jessie amd64
ii puppetlabs-release-pc1 1.0.0-2jessie
ii puppetserver 2.4.0-1puppetlabs1

Generated at Tue Aug 20 09:41:46 PDT 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.