puppet schedule

In Puppet operations, we may need to apply some resources only in given periods of time, such as maintenance windows, specific days of the week, or hours of the day. Puppet has a quite useful, and not too much known, resource for that schedule.

The schedule resource type can be used to define a time period. Once defined, by using the schedule meta parameter we can tell Puppet to apply a given resource only when Puppet is running within the specified schedule.

For example, we can define a daily schedule from 1 AM to 4 AM, and also specify how many times a resource using such schedule should be applied via the repeat parameter, as follows:

schedule { 'maintenance':

  range  => '1 - 4',

  period => daily,

  repeat => 1,


and then apply to to any resource, via the schedule metaparameter:

exec { '/usr/local/bin/daily_maintenance':

  schedule => 'maintenance',


Note that such a piece of code doesn’t guarantee that the command is executed every day, and it doesn’t ensure that this happens at a fixed time. What will happen, is that if the puppet runs on a node, between 1 and 4 AM, then the maintenance exec is applied. Like every other resource type, we can declare as many instances of it as we want, they just need to have different titles.

The full list of attributes is:

schedule { 'title':

  name        => # (namevar) The name of the schedule. The title is used if not set name.

  period      => # The period of repetition for resources on this schedule, valid values:

                      # hourly, daily, weekly, monthly, never.

  periodmatch => # Whether periods should be matched by:

                 # - 'number' (IE: two times in an hour) or by

                 # - 'distance' (IE: two times which are 60 minutes apart)

  range       => # The hour (from 0 to 23) range when to apply a schedule.

                 # Midnight might be crossed with something like 22:00 - 02:00

  repeat      => # How often a given resource may be applied in the schedule

  weekday     => # The days of the week in which the schedule occurs


If we need to always run a specific command we probably better use cron on any similar system’s scheduler, as in this case, we have more control over when and if commands are executed.

There are still use cases for Puppet’s resource type, for example, we can use it to:

*Manage different contents of configurations according to the hour or period

*Trigger system reboots if conditions apply

*Manage backups or other maintenance operations (given the described limitations)

*Manage resources that take a long time to be applied and don’t need to be to continuously enforced.

Relevant Blogs: 

Puppet Kubernetes

Installing package using choco in puppet 

Introduction to YAML 

OpenVAS Installation and configuration

Recent Comments

Trevor Mac says:

Hi, do you know if schedule only works with "exec". All the examples I see are with exec but the documents say can be used with any resource.
I want to manage Firefox upgrades as some users have complained that the browser closes if it upgrades during work hours. I wanted to apply after hours schedule to puppet resource package. If I can't, then I could have package ensure that firefox is 'present' and then have /bin/yum update firefox controlled by a schedule separately. I was just hoping to do it as efficiently as possible and would rather just schedule package => 'latest',

I did try to manage package with schedule and it doesn't complain about anything, but nothing happens in the window where it should upgrade firefox.

Thank you.

Leave a Comment