cron

Module to manage cron jobs via /etc/cron.d/

2,173,501 downloads

3,761 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 5.0.0 (latest)
  • 4.2.0
  • 4.1.0
  • 4.0.0
  • 3.0.0
  • 2.0.0
  • 1.3.1
  • 1.3.0
  • 1.2.0
  • 1.1.1
  • 1.1.0
released Dec 10th 2024
This version is compatible with:
  • Puppet Enterprise 2025.2.x, 2025.1.x, 2023.8.x, 2023.7.x, 2023.6.x, 2023.5.x, 2023.4.x, 2023.3.x, 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x
  • Puppet >= 7.0.0 < 9.0.0
  • , , , , , Gentoo, ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'puppet-cron', '5.0.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add puppet-cron
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install puppet-cron --version 5.0.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download
Tags: cron

Documentation

puppet/cron — version 5.0.0 Dec 10th 2024

Reference

Table of Contents

Classes

  • cron: This class wraps cron::install for ease of use
  • cron::install: This class ensures that the distro-appropriate cron package is installed. This class should not be used directly under normal circumstances. Instead, use the cron class.
  • cron::service: This class managed the cron service. This class should not be used directly under normal circumstances. Instead, use the cron class.

Defined types

  • cron::daily: This type creates a daily cron job via a file in /etc/cron.d
  • cron::hourly: This type creates an hourly cron job via a file in /etc/cron.d
  • cron::job: This type creates a cron job via a file in /etc/cron.d
  • cron::job::multiple: This type creates multiple cron jobs via a single file in /etc/cron.d/
  • cron::monthly: This type creates a monthly cron job via a file in /etc/cron.d
  • cron::weekly: This type creates a cron job via a file in /etc/cron.d

Data types

Classes

cron

This class wraps cron::install for ease of use

Examples

simply include the module
include cron
include it but don't manage the cron package
class { 'cron':
  manage_package => false,
}

Parameters

The following parameters are available in the cron class:

service_name

Data type: String[1]

Can be set to define a different cron service name.

package_name

Data type: String[1]

Can be set to install a different cron package.

manage_package

Data type: Boolean

Can be set to disable package installation.

Default value: true

manage_service

Data type: Boolean

Defines if puppet should manage the service.

Default value: true

service_ensure

Data type: Cron::Service_ensure

Defines if the service should be running.

Default value: 'running'

service_enable

Data type: Cron::Service_enable

Defines if the service should be enabled at boot.

Default value: true

users_allow

Data type: Array[Cron::User]

A list of users which are exclusively able to create, edit, display, or remove crontab files. Only used if manage_users_allow == true.

Default value: []

users_deny

Data type: Array[Cron::User]

A list of users which are prohibited from create, edit, display, or remove crontab files. Only used if manage_users_deny == true.

Default value: []

manage_users_allow

Data type: Boolean

If the /etc/cron.allow should be managed.

Default value: false

manage_users_deny

Data type: Boolean

If the /etc/cron.deny should be managed.

Default value: false

allow_deny_mode

Data type: Stdlib::Filemode

Specify the cron.allow/deny file mode.

Default value: '0644'

merge

Data type: Enum['deep', 'first', 'hash', 'unique']

The lookup() merge method to use with cron job hiera lookups.

Default value: 'hash'

manage_crontab

Data type: Boolean

Whether to manage /etc/crontab

Default value: false

crontab_shell

Data type: Stdlib::Absolutepath

The value for SHELL in /etc/crontab

Default value: '/bin/bash'

crontab_path

Data type: String[1]

The value for PATH in /etc/crontab

Default value: '/sbin:/bin:/usr/sbin:/usr/bin'

crontab_mailto

Data type: String[1]

The value for MAILTO in /etc/crontab

Default value: 'root'

crontab_home

Data type: Optional[Stdlib::Absolutepath]

The value for HOME in /etc/crontab

Default value: undef

crontab_run_parts

Data type: Cron::Run_parts

Define sadditional cron::run_parts resources

Default value: {}

file_mode

Data type: Stdlib::Filemode

The file mode for the system crontab file

Default value: '0644'

dir_mode

Data type: Stdlib::Filemode

The file mode for the cron directories

Default value: '0755'

package_ensure

Data type: Cron::Package_ensure

Default value: 'installed'

cron::install

This class ensures that the distro-appropriate cron package is installed. This class should not be used directly under normal circumstances. Instead, use the cron class.

cron::service

This class managed the cron service. This class should not be used directly under normal circumstances. Instead, use the cron class.

Defined types

cron::daily

This type creates a daily cron job via a file in /etc/cron.d

Examples

create a daily cron job with custom PATH environment variable
cron::daily { 'mysql_backup':
  minute      => '1',
  hour        => '3',
  environment => [ 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"' ],
  command     => 'mysqldump -u root my_db >/backups/my_db.sql',
}

Parameters

The following parameters are available in the cron::daily defined type:

command

Data type: Optional[String[1]]

The command to execute.

Default value: undef

ensure

Data type: Cron::Job_ensure

The state to ensure this resource exists in. Can be absent, present.

Default value: 'present'

minute

Data type: Cron::Minute

The minute the cron job should fire on. Can be any valid cron.

Default value: 0

hour

Data type: Cron::Hour

The hour the cron job should fire on. Can be any valid cron hour value.

Default value: 0

environment

Data type: Cron::Environment

An array of environment variable settings.

Default value: []

user

Data type: Cron::User

The user the cron job should be executed as.

Default value: 'root'

mode

Data type: Stdlib::Filemode

The mode to set on the created job file.

Default value: '0600'

description

Data type: Optional[String]

Optional short description, which will be included in the cron job file.

Default value: undef

cron::hourly

This type creates an hourly cron job via a file in /etc/cron.d

Examples

create a daily cron job with custom PATH environment variable
cron::hourly { 'generate_puppetdoc':
  minute      => '1',
  environment => [ 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"' ],
  command     => 'puppet doc >/var/www/puppet_docs.mkd',
}

Parameters

The following parameters are available in the cron::hourly defined type:

command

Data type: Optional[String[1]]

The command to execute.

Default value: undef

ensure

Data type: Cron::Job_ensure

The state to ensure this resource exists in. Can be absent, present.

Default value: 'present'

minute

Data type: Cron::Minute

The minute the cron job should fire on. Can be any valid cron.

Default value: 0

environment

Data type: Cron::Environment

An array of environment variable settings.

Default value: []

user

Data type: Cron::User

The user the cron job should be executed as.

Default value: 'root'

mode

Data type: Stdlib::Filemode

The mode to set on the created job file.

Default value: '0600'

description

Data type: Optional[String]

Optional short description, which will be included in the cron job file.

Default value: undef

cron::job

This type creates a cron job via a file in /etc/cron.d

Examples

create a cron job
cron::job { 'generate_puppetdoc':
  minute      => '01',
  environment => [ 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"' ],
  command     => 'puppet doc /etc/puppet/modules >/var/www/puppet_docs.mkd',
}

Parameters

The following parameters are available in the cron::job defined type:

command

Data type: Optional[String[1]]

The command to execute.

Default value: undef

ensure

Data type: Cron::Job_ensure

The state to ensure this resource exists in. Can be absent, present.

Default value: 'present'

minute

Data type: Cron::Minute

The minute the cron job should fire on. Can be any valid cron.

Default value: '*'

hour

Data type: Cron::Hour

The hour the cron job should fire on. Can be any valid cron hour.

Default value: '*'

date

Data type: Cron::Date

The date the cron job should fire on. Can be any valid cron date.

Default value: '*'

month

Data type: Cron::Month

The month the cron job should fire on. Can be any valid cron month.

Default value: '*'

weekday

Data type: Cron::Weekday

The day of the week the cron job should fire on. Can be any valid cron weekday value.

Default value: '*'

special

Data type: Cron::Special

A crontab specific keyword like 'reboot'.

Default value: undef

environment

Data type: Cron::Environment

An array of environment variable settings.

Default value: []

user

Data type: Cron::User

The user the cron job should be executed as.

Default value: 'root'

group

Data type: Variant[String[1],Integer[0]]

the group the cron job file should by owned by.

Default value: 0

mode

Data type: Stdlib::Filemode

The mode to set on the created job file.

Default value: '0600'

description

Data type: Optional[String]

Optional short description, which will be included in the cron job file.

Default value: undef

cron::job::multiple

This type creates multiple cron jobs via a single file in /etc/cron.d/

Examples

create multiple cron jobs at once
cron::job::multiple { 'test':
  jobs => [
    {
      minute      => '55',
      hour        => '5',
      date        => '*',
      month       => '*',
      weekday     => '*',
      user        => 'rmueller',
      command     => '/usr/bin/uname',
    },
    {
      command     => '/usr/bin/sleep 1',
    },
    {
      command     => '/usr/bin/sleep 10',
      special     => 'reboot',
    },
  ],
  environment => [ 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"' ],
}

Parameters

The following parameters are available in the cron::job::multiple defined type:

jobs

Data type:

Array[Struct[{
        Optional['command']     => String[1],
        Optional['minute']      => Cron::Minute,
        Optional['hour']        => Cron::Hour,
        Optional['date']        => Cron::Date,
        Optional['month']       => Cron::Month,
        Optional['weekday']     => Cron::Weekday,
        Optional['special']     => Cron::Special,
        Optional['user']        => Cron::User,
        Optional['description'] => String,
  }]]

A hash of multiple cron jobs using the same structure as cron::job and using the same defaults for each parameter.

ensure

Data type: Cron::Job_ensure

The state to ensure this resource exists in. Can be absent, present.

Default value: 'present'

environment

Data type: Cron::Environment

An array of environment variable settings.

Default value: []

mode

Data type: Stdlib::Filemode

The mode to set on the created job file.

Default value: '0600'

cron::monthly

This type creates a monthly cron job via a file in /etc/cron.d

Examples

create a cron job that runs monthly on a 28. day at 7 am and 1 minute
cron::monthly { 'delete_old_log_files':
  minute      => '1',
  hour        => '7',
  date        => '28',
  environment => [ 'MAILTO="admin@example.com"' ],
  command     => 'find /var/log -type f -ctime +30 -delete',
}

Parameters

The following parameters are available in the cron::monthly defined type:

command

Data type: Optional[String[1]]

The command to execute.

Default value: undef

ensure

Data type: Cron::Job_ensure

The state to ensure this resource exists in. Can be absent, present.

Default value: 'present'

minute

Data type: Cron::Minute

The minute the cron job should fire on. Can be any valid cron value.

Default value: 0

hour

Data type: Cron::Hour

The hour the cron job should fire on. Can be any valid cron hour value.

Default value: 0

date

Data type: Cron::Date

The date the cron job should fire on. Can be any valid cron date value.

Default value: 1

environment

Data type: Cron::Environment

An array of environment variable settings.

Default value: []

user

Data type: Cron::User

The user the cron job should be executed as.

Default value: 'root'

mode

Data type: Stdlib::Filemode

The mode to set on the created job file.

Default value: '0600'

description

Data type: Optional[String]

Optional short description, which will be included in the cron job file.

Default value: undef

cron::weekly

This type creates a cron job via a file in /etc/cron.d

Examples

create a weekly cron that runs on the 7th day at 4 am and 1 minute
cron::weekly { 'delete_old_temp_files':
  minute      => '1',
  hour        => '4',
  weekday     => '7',
  environment => [ 'MAILTO="admin@example.com"' ],
  command     => 'find /tmp -type f -ctime +7 -delete',
}

Parameters

The following parameters are available in the cron::weekly defined type:

command

Data type: Optional[String[1]]

The command to execute.

Default value: undef

ensure

Data type: Cron::Job_ensure

The state to ensure this resource exists in. Can be absent, present.

Default value: 'present'

minute

Data type: Cron::Minute

The minute the cron job should fire on. Can be any valid cron.

Default value: 0

hour

Data type: Cron::Hour

The hour the cron job should fire on. Can be any valid cron hour value.

Default value: 0

weekday

Data type: Cron::Weekday

The day of the week the cron job should fire on. Can be any valid cron weekday value.

Default value: 0

user

Data type: Cron::User

The user the cron job should be executed as.

Default value: 'root'

mode

Data type: Stdlib::Filemode

The mode to set on the created job file.

Default value: '0600'

environment

Data type: Cron::Environment

An array of environment variable settings.

Default value: []

description

Data type: Optional[String]

Optional short description, which will be included in the cron job file.

Default value: undef

Data types

Cron::Date

Valid $date (day of month) parameter to Cron::Job.

Alias of

Variant[Integer[1,31], Pattern[/(?x)\A(
    \* ( \/ ( [12][0-9]?|3[01]?|[4-9] ) )?
    |       ( [12][0-9]?|3[01]?|[4-9] ) ( - ( [12][0-9]?|3[01]?|[4-9] ) ( \/ ( [12][0-9]?|3[01]?|[4-9] ) )? )?
       ( ,  ( [12][0-9]?|3[01]?|[4-9] ) ( - ( [12][0-9]?|3[01]?|[4-9] ) ( \/ ( [12][0-9]?|3[01]?|[4-9] ) )? )? )*
  )\z/]]

Cron::Deb_version

Valid .deb version string. See https://www.debian.org/doc/debian-policy/#s-f-version

Alias of Pattern[/(?i:\A(((0|[1-9][0-9]*):)?[0-9]([a-z0-9.+-~]*|[a-z0-9.+~]*-[a-z0-9+.~]+))\z)/]

Cron::Environment

Valid $environment parameter to Cron::Job.

Alias of Array[Variant[Pattern[/(?i:\A[a-z_][a-z0-9_]*=[^\0]*\z)/],Sensitive[Pattern[/(?i:\A[a-z_][a-z0-9_]*=[^\0]*\z)/]]]]

Cron::Hour

Valid $hour parameter to Cron::Job.

Alias of

Variant[Integer[0,23], Pattern[/(?x)\A(
    \* ( \/ ( 1[0-9]|2[0-3]|[1-9] ) )?
    |       ( 1?[0-9]|2[0-3] ) ( - ( 1?[0-9]|2[0-3] ) ( \/ ( 1[0-9]|2[0-3]|[1-9] ) )? )?
        ( , ( 1?[0-9]|2[0-3] ) ( - ( 1?[0-9]|2[0-3] ) ( \/ ( 1[0-9]|2[0-3]|[1-9] ) )? )? )*
  )\z/]]

Cron::Job_ensure

Valid $ensure parameter to Cron::Job.

Alias of Enum['absent', 'present']

Cron::Jobname

Valid $title parameter to Cron::Job. This is the name of the /etc/cron.d/ file. The Ubuntu run-parts manpage specifies (^[a-zA-Z0-9_-]+$). For Cronie, the documentation is (unfortunately) in the code:

Alias of Pattern[/(?i:\A[a-z0-9_-]{1,255}\z)/]

Cron::Minute

Valid $minute parameter to Cron::Job.

Alias of

Variant[Integer[0,59], Pattern[/(?x)\A(
    \* ( \/ ( [1-5][0-9]?|[6-9] ) )?
    |         [1-5]?[0-9] ( - [1-5]?[0-9] ( \/ ( [1-5][0-9]?|[6-9] ) )? )?
        ( ,   [1-5]?[0-9] ( - [1-5]?[0-9] ( \/ ( [1-5][0-9]?|[6-9] ) )? )? )*
  )\z/]]

Cron::Month

Valid $month parameter to Cron::Job.

Alias of

Variant[Cron::Monthname, Integer[1,12], Pattern[/(?x)\A(
    \* ( \/ ( 1[012]?|[2-9] ) )?
    |       ( 1[012]?|[2-9] ) ( - ( 1[012]?|[2-9] ) ( \/ ( 1[012]?|[2-9] ) )? )?
        ( , ( 1[012]?|[2-9] ) ( - ( 1[012]?|[2-9] ) ( \/ ( 1[012]?|[2-9] ) )? )? )*
  )\z/]]

Cron::Monthname

Short-names for each month.

Alias of Enum['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

Cron::Package_ensure

Valid $service_ensure parameter to Cron.

Alias of Variant[Cron::Package_state, Cron::Deb_version, Cron::Rpm_version]

Cron::Package_state

Valid $ensure parameter to Package resource. Excludes version numbers.

Alias of Enum['absent', 'installed', 'held', 'latest', 'present', 'purged']

Cron::Rpm_version

Valid .rpm version string. See http://www.perlmonks.org/?node_id=237724

Alias of Pattern[/\A[^-]+(-[^-])?\z/]

Cron::Run_parts

Valid element of $crontab_run_parts parameter to Class['cron'].

Alias of

Hash[Cron::Jobname, Struct[{
    NotUndef['user']       => Cron::User,
    Optional['minute']     => Cron::Minute,
    Optional['hour']       => Cron::Hour,
    Optional['dayofmonth'] => Cron::Date,
    Optional['month']      => Cron::Month,
    Optional['dayofweek']  => Cron::Weekday,
  }]]

Cron::Second

Valid $second parameter to Cron::Job.

Alias of Cron::Minute

Cron::Service_Enable

Valid $service_enable parameter to Cron.

Alias of Variant[Boolean, Enum['manual','mask']]

Cron::Service_ensure

Valid $service_ensure parameter to Cron.

Alias of Variant[Boolean, Enum['running','stopped']]

Cron::Special

Valid $special parameter to Cron::Job.

Alias of

Optional[Enum['annually',
    'daily',
    'hourly',
    'midnight',
    'monthly',
    'reboot',
    'weekly',
    'yearly',
  ]]

Cron::User

Valid $user parameter to Cron::Job.

Alias of Pattern[/(?i:\A\w[a-z0-9_\.-]{0,30}[a-z0-9_$-]\z)/]

Cron::Weekday

Valid $weekday parameter to Cron::Job.

Alias of

Variant[Cron::Weekdayname, Integer[0,7], Pattern[/(?x)\A(
    \* ( \/ [1-7] )?
    |       [0-7] ( - [0-7] ( \/ [1-7] )? )?
        ( , [0-7] ( - [0-7] ( \/ [1-7] )? )? )*
  )\z/]]

Cron::Weekdayname

Short names for each day of the week.

Alias of Enum['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']