Version information
This version is compatible with:
- Puppet Enterprise 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.4.x
- Puppet >= 4.9.1 < 6.0.0
- Gentoo, , , , , ,
This module has been deprecated by its author since Mar 2nd 2018.
The author has suggested puppet-cron as its replacement.
Start using this module
Documentation
Puppet Cron Module
Notes
This module manages cronjobs by placing files in /etc/cron.d
.
It is a detached fork of torrancew/puppet-cron which seems to be abandoned.
This fork is Puppet 4 / future parser compatible.
The current version (starting with v1.0.0) of this module requires Puppet 4.9.1 or greater.
If you are using an older version of Puppet you can pin the version to v0.2.1 which was still compatible with much older Puppet versions.
You can browse the documentation of that version in the v0.2.x branch here.
This module supports configuration of cronjobs via Hiera as well.
For that you need to declare the cron
class.
This module defines the following types:
cron::job
- basic job resourcecron::job::multiple
- basic job resource for multiple jobs per filecron::hourly
- wrapper for hourly jobscron::daily
- wrapper for daily jobscron::weekly
- wrapper for weekly jobscron::monthly
- wrapper for monthly jobs
Installation
As usual use puppet module install rmueller-cron
to install it.
Usage
The title of the job (e.g. cron::job { 'title':
) is completely arbitrary. However, there can only be one cron job by that name.
The file in /etc/cron.d/
will be created with the $title
as the file name.
Keep that in mind when choosing the name to avoid overwriting existing system cronjobs and use characters that don't cause problems when used in filenames.
cron
If you want the class to automatically install the correct cron package you can declare the cron
class. By default it will then install the right package.
If you want to use Hiera to configure your cronjobs, you must declare the cron
class.
You can disable the managment of the cron package by setting the manage_package
parameter to false
.
You can also specify a different cron package name via package_name
.
By default we try to select the right one for your distribution.
But in some cases (e.g. Gentoo) you might want to overwrite it here.
This class allows specifiying the following parameter:
manage_package
- optional - defaults to "true"package_ensure
- optional - defaults to "installed"package_name
- optional - defaults to OS specific default package nameservice_name
- optional - defaults to OS soecific default service namemanage_service
- optional - defaults to "true"service_enable
- optional - defaults to "true"service_ensure
- optional - defaults to "running"manage_users_allow
- optional - defaults to false, whether to manange/etc/cron.allow
manage_users_deny
- optional - defaults to false, whether to manange/etc/cron.deny
users_allow
- optional - An array of users to add to/etc/cron.allow
users_deny
- optional - An array of users to add to/etc/cron.deny
Examples:
include cron
or:
class { 'cron':
manage_package => false,
}
cron::job
cron::job
creates generic jobs in /etc/cron.d
.
It allows specifying the following parameters:
ensure
- optional - defaults to "present"command
- required - the command to executeminute
- optional - defaults to "*"hour
- optional - defaults to "*"date
- optional - defaults to "*"month
- optional - defaults to "*"weekday
- optional - defaults to "*"special
- optional - defaults to undefuser
- optional - defaults to "root"environment
- optional - defaults to ""mode
- optional - defaults to "0644"description
- optional - defaults to undef
Example:
This would create the file /etc/cron.d/mysqlbackup
and run the command mysqldump -u root mydb
as root at 2:40 AM every day:
cron::job { 'mysqlbackup':
minute => '40',
hour => '2',
date => '*',
month => '*',
weekday => '*',
user => 'root',
command => 'mysqldump -u root mydb',
environment => [ 'MAILTO=root', 'PATH="/usr/bin:/bin"', ],
description => 'Mysql backup',
}
Hiera example:
---
cron::job:
'mysqlbackup':
command: 'mysqldump -u root mydb'
minute: 0
hour: 0
date: '*'
month: '*'
weekday: '*'
user: root
environment:
- 'MAILTO=root'
- 'PATH="/usr/bin:/bin"'
description: 'Mysql backup'
cron::job::multiple
cron:job::multiple
creates a file in /etc/cron.d
with multiple cron jobs configured in it.
It allows specifiying the following parameters:
ensure
- optional - defaults to "present"jobs
- required - an array of hashes of multiple cron jobs using a similar structure ascron::job
-parametersenvironment
- optional - defaults to ""mode
- optional - defaults to "0644"
And the keys of the jobs hash are:
command
- required - the command to executeminute
- optional - defaults to "*"hour
- optional - defaults to "*"date
- optional - defaults to "*"month
- optional - defaults to "*"weekday
- optional - defaults to "*"special
- optional - defaults to undefuser
- optional - defaults to "root"description
- optional - defaults to undef
Example:
cron::job::multiple { 'test_cron_job_multiple':
jobs => [
{
minute => '55',
hour => '5',
date => '*',
month => '*',
weekday => '*',
user => 'rmueller',
command => '/usr/bin/uname',
description => 'print system information',
},
{
command => '/usr/bin/sleep 1',
description => 'Sleeping',
},
{
command => '/usr/bin/sleep 10',
special => 'reboot',
},
],
environment => [ 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"' ],
}
Hiera example:
---
cron::job::multiple:
'test_cron_job_multiple':
jobs:
- {
minute: 55,
hour: 5,
date: '*',
month: '*',
weekday: '*',
user: rmueller,
command: '/usr/bin/uname',
description: 'print system information',
}
- {
command: '/usr/bin/sleep 1',
description: 'Sleeping',
}
- {
command: '/usr/bin/sleep 10',
special: 'reboot',
}
environment:
- 'PATH="/usr/sbin:/usr/bin:/sbin:/bin"'
That will generate the file /etc/cron.d/test_cron_job_multiple
with essentially this content:
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
55 5 * * * rmueller /usr/bin/uname
* * * * * root /usr/bin/sleep 1
@reboot root /usr/bin/sleep 10
cron::hourly
cron::hourly
creates jobs in /etc/cron.d
that run once per hour.
It allows specifying the following parameters:
ensure
- optional - defaults to "present"command
- required - the command to executeminute
- optional - defaults to "0"user
- optional - defaults to "root"environment
- optional - defaults to ""mode
- optional - defaults to "0644"description
- optional - defaults to undef
Example:
This would create the file /etc/cron.d/mysqlbackup_hourly
and run the command mysqldump -u root mydb
as root on the 20th minute of every hour:
cron::hourly { 'mysqlbackup_hourly':
minute => '20',
user => 'root',
command => 'mysqldump -u root mydb',
environment => [ 'MAILTO=root', 'PATH="/usr/bin:/bin"', ],
}
Hiera example:
---
cron::hourly:
'mysqlbackup_hourly':
minute: 20
user: root
command: 'mysqldump -u root mydb'
environment:
- 'MAILTO=root'
- 'PATH="/usr/bin:/bin"'
cron::daily
cron::daily
creates jobs in /etc/cron.d
that run once per day.
It allows specifying the following parameters:
ensure
- optional - defaults to "present"command
- required - the command to executeminute
- optional - defaults to "0"hour
- optional - defaults to "0"user
- optional - defaults to "root"environment
- optional - defaults to ""mode
- optional - defaults to "0644"description
- optional - defaults to undef
Example:
This would create the file /etc/cron.d/mysqlbackup_daily
and run the command mysqldump -u root mydb
as root at 2:40 AM every day, like the above generic example:
cron::daily { 'mysqlbackup_daily':
minute => '40',
hour => '2',
user => 'root',
command => 'mysqldump -u root mydb',
}
Hiera example:
---
cron::daily:
'mysqlbackup_daily':
minute: 40
hour: 2
user: root
command: 'mysqldump -u root mydb'
cron::weekly
cron::weekly
creates jobs in /etc/cron.d
that run once per week.
It allows specifying the following parameters:
ensure
- optional - defaults to "present"command
- required - the command to executeminute
- optional - defaults to "0"hour
- optional - defaults to "0"weekday
- optional - defaults to "0"user
- optional - defaults to "root"environment
- optional - defaults to ""mode
- optional - defaults to "0644"description
- optional - defaults to undef
Example:
This would create the file /etc/cron.d/mysqlbackup_weekly
and run the command mysqldump -u root mydb
as root at 4:40 AM every Sunday, like the above generic example:
cron::weekly { 'mysqlbackup_weekly':
minute => '40',
hour => '4',
weekday => '0',
user => 'root',
command => 'mysqldump -u root mydb',
}
Hiera example:
---
cron::weekly:
'mysqlbackup_weekly':
minute: 40
hour: 4
weekday: 0
user: root
command: 'mysqldump -u root mydb'
cron::monthly
cron::monthly
creates jobs in /etc/cron.d
that run once per month.
It allows specifying the following parameters:
ensure
- optional - defaults to "present"command
- required - the command to executeminute
- optional - defaults to "0"hour
- optional - defaults to "0"date
- optional - defaults to "1"user
- optional - defaults to "root"environment
- optional - defaults to ""mode
- optional - defaults to "0644"description
- optional - defaults to undef
Example:
This would create the file /etc/cron.d/mysqlbackup_monthly
and run the command mysqldump -u root mydb
as root at 3:40 AM the 1st of every month, like the above generic example:
cron::monthly { 'mysqlbackup_monthly':
minute => '40',
hour => '3',
date => '1',
user => 'root',
command => 'mysqldump -u root mydb',
}
Hiera example:
---
cron::monthly:
'mysqlbackup_monthly':
minute: 40
hour: 3
date: 1
user: root
command: 'mysqldump -u root mydb'
Contributors
- Kevin Goess (@kgoess) - Environment variable support + fixes
- Andy Shinn (@andyshinn) - RedHat derivatives package name fix
- Chris Weyl (@RsrchBoy) - Fixed Puppet 3.2 deprecation warnings
- Mathew Archibald (@mattyindustries) - Fixed file ownership issues
- The Community - Continued improvement of this module via bugs and patches
v1.0.0: 2017-10-14 Changes:
- BREAK: Requires Puppet version >=4.9.1
- Added type-hinting to all manifest parameters
- Added management of /etc/cron.allow and /etc/cron.deny
- Replaced hiera_hash() with lookup() calls
- Replaced params.pp with in-module data (Hiera 5)
- Replaced create_resources with iterators
- Replaced anchor pattern with contain
- Made the cron::job command attribute optional
v0.2.1: 2017-07-30 Changes:
- Added support for special time options
- Rspec fixes
v0.2.0: 2016-11-22 Changes:
- BREAK: Added cron service managment The cron service is now managed by this module and by default the service will be started
- Rspec fixes
v0.1.8: 2016-06-26 Changes:
- Added support for Scientific Linux
v0.1.7: 2016-06-12 Changes:
- Properly support Gentoo
- Documentation fixes
- Rspec fixes
v0.1.6: 2016-04-10 Changes:
- Added description parameters
v0.1.5: 2016-03-06 Changes:
- Fix release on forge
v0.1.4: 2016-03-06 Changes:
- Added possibility to add jobs from hiera
- Added Debian as supported operating system
- Allow declaration of cron class without managing the cron package
- Properly detect RHEL 5 based cron packages
- Fix puppet-lint warnings
- Add more tests
v0.1.3: 2015-09-20 Changes:
- Support for multiple cron jobs in a single file added (cron::job::multiple)
- Make manifest code more readable
- Change header in template to fit standard 80 char wide terminals
- Extend README.md
v0.1.2: 2015-08-13 Changes:
- Update to new style of Puppet modules (metadata.json)
v0.1.1: 2015-07-12 Changes:
- Make module Puppet 4 compatible
- Fix Travis CI integration
v0.1.0: 2013-08-27 Changes:
- Add support for the "ensure" parameter
v0.0.3: 2013-07-04 Changes:
- Make job files owned by root
- Fix warnings for Puppet 3.2.2
v0.0.2: 2013-05-11 Changes:
- Make mode of job file configurable
v0.0.1: 2013-03-02 Changes:
- Initial PuppetForge release
Copyright 2012-2013 Tray Torrance Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.