voxpupuli / puppet-cron Goto Github PK
View Code? Open in Web Editor NEWPuppet module to manage cron jobs via /etc/cron.d
Home Page: https://forge.puppet.com/puppet/cron
License: Apache License 2.0
Puppet module to manage cron jobs via /etc/cron.d
Home Page: https://forge.puppet.com/puppet/cron
License: Apache License 2.0
Would it be possible (or accepted even) to add support for managing /etc/anacrontab
on RHEL based systems if we'd like to be able to set things there?
/etc/anacrontab
and according to https://man7.org/linux/man-pages/man5/anacrontab.5.html
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
I'm happy to make an attempt at adding this type of support if it would be accepted.
as the subject, currently it doesn't support this, and having this support would be great, as I run some crons on startup.
Cheers
Thanks for forking and continued work on this module!
If you have an hour or minute expression with comma like 0,5,10,15 you get a type failure because the Cron::Hour and Cron::Minute types does not allow comma in the expression. It is a valid cron expression though.
For example:
Every hour at minutes 15, 30 and 45 (15,30,45 * ? * *)
cron::job { 'myjob':
minute => '15,30,45',
hour => '',
date => '',
month => '',
weekday => '',
user => 'root',
command => 'my-command,
environment => [ 'MAILTO=root', 'PATH="/usr/bin:/bin"', ],
}
Would it break the intension of the type pattern matching to allow comma?
Valid $minute parameter to Cron::Job.
type Cron::Minute = Variant[
Integer[0,59],
Pattern[/\A(([0-9]|[1-5][0-9])|(*|(([0-9]|[1-5][0-9])-([0-9]|[1-5][0-9])))(/([1-9]|[1-5][0-9]))?)\z/]
]
See PR #21
cron::job { 'duplicity-inc':
minute => fqdn_rand(60),
hour => fqdn_rand(4),
weekday => '1,2,3,4,5,6',
user => 'root',
command => '/usr/local/scripts/run-backup-to-b2 inc',
}
Error: Could not find group root
Info: Unknown failure using insync_values? on type: File[job_duplicity-inc] / property: group to compare values ["root"] and 0
Error: /Stage[main]/Duplicity/Cron::Job[duplicity-inc]/File[job_duplicity-inc]/group: change from 'wheel' to 'root' failed: Could not find group root
Successful run.
FreeBSD gid 0 is wheel
, not root
.
(On Puppet 7.0 or later)
Attempt to install the module:
puppet module install puppet-cron
Alternatively, with an earlier version of puppet-cron installed, upgrade to Puppet 7 from an earlier version then attempt to upgrade puppet-cron
puppet module install puppet-cron
Installation / upgrade fails.
Successful installation of / upgrade to the puppet-cron 2.0.0 or later
In the upgrade case, the error output is:
Error: Could not upgrade module 'puppet-cron' (v1.3.1 -> latest)
There are 1 newer versions
No combination of dependency upgrades would satisfy all dependencies
Use `puppet module upgrade --force` to upgrade only this module
My first guess would be that the module is already compatible with Puppet 7 in practice, so that a metadata-only update will resolve the issue.
The CIS benchmarks specifies specific permissions on the default cron files. It would be usefull if this module could implement such functionality to allow you to manage it if you wanted in addition to managing cron files.
Hello! How can I use comma into cronjob? I just want to enumerate some dates in the schedule.
For example, this is my erb template:
some_cronjob:
minute: 0
hour: 0
date: 1,16
command: "some_command"
And I got this:
0 0 116 * * root some_command
Commas are ignored. I just need to enumerate days.
What do i need? Thanks for answer in advance!
Using concat (file fragments) provided by a defined type would allow multiple applications to specify their own application accounts to be added to cron.allow and/or cron.deny without having to know anything about any other application on the system.
When building cron.allow or cron.deny based on templates one has to compile all possible system users in Hiera manually to ensure that they all get added. This is more difficult to manage.
cron module doesn't allow the following pattern, which is a valid syntax
hour => '1-23/2'
Would it be possible to change this feature to enabled?
Maybe a prefix puppet_ ?
Thanks for for taking on DEV of this project.
Trying to create a cronjob with the tilde, which tells cron to use a random valid number
Randomization of the execution time within a range can be used. A random number within a range specified as two numbers separated with a tilde is picked. The specified range is inclusive. For example, 6~15 for a 'minutes' entry picks a random minute within 6 to 15
range. The random number is picked when crontab file is parsed. The first number must be less than or equal to the second one. You might omit one or both of the numbers specifying the range. For example, ~ for a 'minutes' entry picks a random minute within 0 to 59
range.
Error: Evaluation Error: Error while evaluating a Resource Statement, Cron::Job::Multiple[production_atq_adc_send_missing_doc]: parameter 'jobs' index 0 entry 'minute' expects a Cron::Minute = 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/]] value, got String (file: /etc/puppetlabs/code/environments/branch1/site-modules/blabla/manifests/cron.pp, line: 17) on node atqrh8phpp1.atqlan.agri-tracabilite.qc.ca
Accept the tilde
I notice that cron_core is included with puppet-agent whereas this module must be explicitly loaded.
Please provide a comparison between the two modules, noting which is preferred for different use-cases.
Noticed while upgrading from 4.1.0 to 4.2.0 that the only change in the contents of our cron jobs is now there is an empty line at the end of the file. Is this intentional?
Looks like it's coming from here, and I don't see the same thing in the old ERB template or in the multiple EPP template either.
An evaluation problem running puppet apply command
No evaluation error
Error: Evaluation Error: Resource type not found: Cron::Special (file: /etc/puppetlabs/code/modules/cron/manifests/job.pp, line: 30, column: 3)
I have downgraded the module to 4.0.0 and the problem went away
Hi.
I was wondering if you would accept a PR bringing /etc/crontab
management (on Debian) in this module?
For example I currently do something like this:
# Class: profile::base::cron
class profile::base::cron {
include ::cron
$crontab_environment = lookup(
'cron::crontab_environment', Array[String], undef,
[
'SHELL="/bin/sh"',
'PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"',
]
)
$crontab_hourly_time = lookup(
'cron::crontab_hourly_time', Integer[0,59], undef,
fqdn_rand(60, 'crontab hourly')
)
$crontab_daily_time = lookup(
'cron::crontab_daily_time', Integer[0,59], undef,
fqdn_rand(60, 'crontab daily')
)
$crontab_weekly_time = lookup(
'cron::crontab_weekly_time', Integer[0,59], undef,
fqdn_rand(60, 'crontab weekly')
)
$crontab_monthly_time = lookup(
'cron::crontab_monthly_time', Integer[0,59], undef,
fqdn_rand(60, 'crontab monthly')
)
file { '/etc/crontab':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('profile/base/cron/crontab.erb'),
require => Class['::cron'],
}
}
# This file is managed by Puppet. DO NOT EDIT.
<%- if not @crontab_environment.nil? -%>
<%- @crontab_environment.each do |env| -%>
<%= env %>
<%- end -%>
<%- end -%>
<%= @crontab_hourly_time %> * * * * root cd / && run-parts --report /etc/cron.hourly
<%= @crontab_daily_time %> 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
<%= @crontab_weekly_time %> 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
<%= @crontab_monthly_time %> 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Please let me know if this is something that you could accept (of course I would make this more generic).
Anyway your module is great!
Info:
Puppet Version: 3.7.3
Module Version: 0.2.0
There's an issue that arises within init.pp upon a hiera lookup, as the type expected is a hash, which is not covered by 'undef'. Current code:
$cron_job_multiple = hiera_hash('cron::job::multiple', undef) if $cron_job_multiple { create_resources('cron::job::multiple', $cron_job_multiple) }
This gives back an evaluation error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, create_resources(): second argument must be a hash at...
Potential Fix:
$cron_job_multiple = hiera_hash('cron::job::multiple', {}) if $cron_job_multiple { create_resources('cron::job::multiple', $cron_job_multiple) }
I have successfully replaced the default option to be an empty hash, but I'm not sure if there is a nicer way to do it. I'm happy to submit a PR to get this fixed if you are happy with the solution.
E: @apazga - this was your commit, do you happen to have any input? thanks :)
@roman-mueller I've been reviving my cron
and account
modules, and see that this is the current incarnation of a PR I neglected long ago. Would you have any interest in re-merging upstream?
class { 'cron':
manage_package => false,
}
cron::job { 'test_resource':
command => '/usr/sbin/sleep 1',
user => 'sch',
hour => 2,
minute => 0,
}
Error: Could not set 'file' on ensure: Could not find group root (file: /etc/puppetlabs/code/environments/production/modules/cron/manifests/job.pp, line: 70)
Wrapped exception:
Could not find group root
Error: /Stage[main]/Main/Node[storage2.domain.com]/Cron::Job[test_resource]/File[job_test_resource]/ensure: change from 'absent' to 'file' failed: Could not set 'file' on ensure: Could not find group root (file: /etc/puppetlabs/code
/environments/production/modules/cron/manifests/job.pp, line: 70)
The 'file' resource declared in job.pp uses the fixed value 'root' for the 'group' parameter, but FreeBSD system uses the group 'wheel' and there is no group 'root'.
A possible solution is to define a group based on the $::osfamily fact.
The manifest job.pp might be modifed as follows
--- job_linux.pp 2022-06-28 09:35:31.984345992 +0000
+++ job.pp 2022-06-28 09:21:08.241957487 +0000
@@ -59,6 +59,15 @@
assert_type(Cron::Jobname, $title)
+ case $::osfamily {
+ 'FreeBSD': {
+ $groupname = 'wheel'
+ }
+ default: {
+ $groupname = 'root'
+ }
+ }
+
case $ensure {
'absent': {
file { "job_${title}":
@@ -70,7 +79,7 @@
file { "job_${title}":
ensure => 'file',
owner => 'root',
- group => 'root',
+ group => $groupname,
mode => $mode,
path => "/etc/cron.d/${title}",
content => template('cron/job.erb'),
cron::job:
'solrbackup':
command: 'curl "http://node:8983/solr/admin/collections?action=BACKUP&name=solr-collection-`date +\%Y\%m\%d-\%H\%M`&collection=solr-collection&location=/var/solr/backups"'
minute: '*/10'
hour: '*'
date: '*'
month: '*'
weekday: '*'
user: solr
description: "solr-collection backup"
it should add cron
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Syntax error at '/' at /etc/puppetlabs/code/environments/production/modules/cron/types/hour.pp:4:11 on node
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
While systemd timers are the preferred method on modern Linux OSes and /etc/cron.d is a supported method, some application vendors still require that users have their own cron jobs in /var/spool/cron/.
I have an application that creates an application user that has to manage its own cron jobs. Since all files in /etc/cron.d are owned by root, the non-root users cannot manage their own cron jobs.
puppetlabs-cron_core cannot co-exist with puppet-cron so using puppetlabs-cron_core one loses the ability to manage /etc/cron.allow.
Wouldn't it be fairly trivial to support the old style /var/spool/cron/ methodology?
This was motivated by a colleague's misunderstanding of allowed filename patterns for /etc/cron.d/
files.
I did some research on what exact values are allowed for each parameter to Cron::Job and created appropriate named data types for each.
See #29
Now that we have validation on the special parameter to cron::job, it is enforcing a value with an '@' symbol e.g. @reboot. However, the template already has the '@' symbol prepended to the special cron jobs. This means we get two @ symbols instead of one which is incorrect i believe.
We should either edit the cron::special type and remove the '@'s or edit the template and remove the @ from there.
Hello,
Seems you missed the tags for release v0.1.4, v0.1.5, v0.1.6 and v0.1.7.... Could you please add them (and update your release plans if any). I heavily use r10k to manage my environments, so tags are quite important for me. Cheers ;)
git tag -a v0.1.4 e558e07
git tag -a v0.1.5 2bb009c
git tag -a v0.1.6 9946ed6
git tag -a v0.1.7 bf3643d
README says:
jobs - required - a hash of multiple cron jobs using a similar structure as cron::job-parameters
But shouldn't this read:
jobs - required - an array of hashes of multiple cron jobs using a similar structure as cron::job-parameters
Hello,
we have a classical module with a manifest and I try to add a user for users_allow, but I have a bit trouble to get it working, without hiera (role.yaml).
In our base class, we call the cron class with some defaults, like manage allow/deny. In our common.yaml, I added the user root, for allowed crons, but now I want to add it also to our module, like:
class cron::users_allow inherits cron {
class { cron: users_allow => ['egg'] }
}
but, it won't work. It adds only the user "root" from the common.yaml and that's it. I don't want to add it to the role, because this option fits better to our module.
Any suggestions, what I have done wrong ?
cu denny
cron::job::multiple { 'osbackup':
jobs => [
{
minute => 30,
hour => 23,
weekday => [0, 1, 2, 3, 4, 5],
user => 'root',
command => '/opt/sndr/tools/osbackup -a -i linux > /var/log/osbackup-linux-cron.log 2>&1',
description => 'Operating system backup Sunday-Friday for Linux',
},
],
}
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Cron::Job::Multiple[osbackup]:
parameter 'jobs' index 0 entry 'weekday' expects a Cron::Weekday = Variant[Cron::Weekdayname = Enum['Fri', 'Mon', 'Sat', 'Sun', 'Thu', 'Tue', 'Wed'], Integer[0, 7], Pattern[/(?x)\A(
* ( / [1-7] )?
| [0-7] ( - [0-7] ( / [1-7] )? )?
( , [0-7] ( - [0-7] ( / [1-7] )? )? )*
)\z/]] value, got Tuple
parameter 'jobs' index 2 entry 'weekday' expects a Cron::Weekday = Variant[Cron::Weekdayname = Enum['Fri', 'Mon', 'Sat', 'Sun', 'Thu', 'Tue', 'Wed'], Integer[0, 7], Pattern[/(?x)\A(
* ( / [1-7] )?
| [0-7] ( - [0-7] ( / [1-7] )? )?
( , [0-7] ( - [0-7] ( / [1-7] )? )? )*
)\z/]] value, got Tuple (file: /etc/puppetlabs/code/environments/feature_c01393_cron_multi/modules/hpsu_linux_base/manifests/cron.pp, line: 46) on node cbclnxadmin.schneider.com
A weekday value in cron entry:
30 23 * * 0,1,2,3,4,5 /opt/sndr/tools/osbackup -a -i linux > /var/log/osbackup-linux-cron.log 2>&1
In init.pp, there are lookups and instantiations for each cron interval defined type, but they don't match the actual defined types for hourly, daily, weekly and monthly.
I.e. in init.pp you have "cron::job::hourly" but the actual type is "cron::hourly".
cron::weekly:
'reload_httpd_to_reload_certificates':
command: '/usr/sbin/service apache24 graceful'
Info: /Stage[main]/Cron::Service/Service[cron]: Unscheduling refresh on Service[cron]
Error: Could not find group root
Error: /Stage[main]/Cron/Cron::Weekly[reload_httpd_to_reload_certificates]/Cron::Job[reload_httpd_to_reload_certificates]/File[job_reload_httpd_to_reload_certificates]/group: change from 'wheel' to 'root' failed: Could not find group root
Info: Class[Cron]: Unscheduling all events on Class[Cron]
## What behaviour did you expect instead
This has already been fixed in #86 , but remains as of yet, unreleased.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.