GithubHelp home page GithubHelp logo

voxpupuli / puppet-cron Goto Github PK

View Code? Open in Web Editor NEW
14.0 45.0 39.0 387 KB

Puppet module to manage cron jobs via /etc/cron.d

Home Page: https://forge.puppet.com/puppet/cron

License: Apache License 2.0

Ruby 52.95% Puppet 37.99% HTML 4.77% Pascal 4.29%
linux-puppet-module puppet hacktoberfest bsd-puppet-module centos-puppet-module debian-puppet-module freebsd-puppet-module gentoo-puppet-module redhat-puppet-module scientific-puppet-module

puppet-cron's Introduction

Puppet Cron Module

License Build Status Puppet Forge Puppet Forge - downloads Puppet Forge - scores

Notes

This module manages cronjobs by placing files in /etc/cron.d. rmueller-cron was a detached fork of torrancew/puppet-cron After v1.0.0, the module was migrated to Vox Pupuli where it is now maintained and released under the puppet namespace.

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 resource
  • cron::job::multiple - basic job resource for multiple jobs per file
  • cron::hourly - wrapper for hourly jobs
  • cron::daily - wrapper for daily jobs
  • cron::weekly - wrapper for weekly jobs
  • cron::monthly - wrapper for monthly jobs

Installation

As usual use puppet module install puppet-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 management 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.

Examples:

  include cron

or:

  class { 'cron':
    manage_package => false,
  }

Add custom crontab run-parts

class { 'cron':
  manage_crontab    => true,
  crontab_run_parts => {'5min' => { 'user' => 'root', 'minute' => '*/5' }},
}

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 execute
  • minute - optional - defaults to "*"
  • hour - optional - defaults to "*"
  • date - optional - defaults to "*"
  • month - optional - defaults to "*"
  • weekday - optional - defaults to "*"
  • special - optional - defaults to undef
  • user - optional - defaults to "root"
  • environment - optional - defaults to ""
  • mode - optional - defaults to "0600"
  • 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 specifying the following parameters:

  • ensure - optional - defaults to "present"
  • jobs - required - an array of hashes of multiple cron jobs using a similar structure as cron::job-parameters
  • environment - optional - defaults to ""
  • mode - optional - defaults to "0600"

And the keys of the jobs hash are:

  • command - required - the command to execute
  • minute - optional - defaults to "*"
  • hour - optional - defaults to "*"
  • date - optional - defaults to "*"
  • month - optional - defaults to "*"
  • weekday - optional - defaults to "*"
  • special - optional - defaults to undef
  • user - 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 execute
  • minute - optional - defaults to "0"
  • user - optional - defaults to "root"
  • environment - optional - defaults to ""
  • mode - optional - defaults to "0600"
  • 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 execute
  • minute - optional - defaults to "0"
  • hour - optional - defaults to "0"
  • user - optional - defaults to "root"
  • environment - optional - defaults to ""
  • mode - optional - defaults to "0600"
  • 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 execute
  • minute - 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 "0600"
  • 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 execute
  • minute - 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 "0600"
  • 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

puppet-cron's People

Contributors

alexjfisher avatar bastelfreak avatar capull0 avatar daisukixci avatar dhollinger avatar dhoppe avatar ekohl avatar elmobp avatar flipez avatar ghoneycutt avatar igalic avatar jcbollinger avatar jcpunk avatar kenyon avatar ludovicus3 avatar mleklund avatar pillarsdotnet avatar ralfbosz avatar roman-mueller avatar rvicinus avatar rwaffen avatar sandra-thieme avatar scorillo avatar sebastianrakel avatar smortex avatar timogoebel avatar tragiccode avatar trevor-vaughan avatar treydock avatar zilchms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-cron's Issues

Small patch to support FreeBSD cron job file group attribute

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7.11
  • Ruby: 2.7.5
  • Distribution: FreeBSD 13
  • Module version: 2.0.0

How to reproduce (e.g Puppet code you use)

class { 'cron':
manage_package => false,
}
cron::job { 'test_resource':
command => '/usr/sbin/sleep 1',
user => 'sch',
hour => 2,
minute => 0,
}

What are you seeing

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)

What behaviour did you expect instead

Output log

Any additional information you'd like to impart

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: users_allow -> overwrite in module manifest (without hiera)

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

Special to support @startup

as the subject, currently it doesn't support this, and having this support would be great, as I run some crons on startup.

Cheers

Can't get weekday options to work as an array of days

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 2019.7
  • Ruby: ?
  • Distribution: Linux
  • Module version: 2.0.0

How to reproduce (e.g Puppet code you use)

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',
},
],
}

What are you seeing

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

What behaviour did you expect instead

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

Output log

Any additional information you'd like to impart

Usage of 'undef' for for a hash

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 :)

Code in init.pp doesn't match defined types

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".

Open to merging back upstream?

@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?

Support for /var/spool/cron

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?

Resource type not found: Cron::Special

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7.26.0
  • Ruby: 2.7.8
  • Distribution: Ubuntu 18.04
  • Module version: 4.1.0

How to reproduce (e.g Puppet code you use)

What are you seeing

An evaluation problem running puppet apply command

What behaviour did you expect instead

No evaluation error

Output log

Error: Evaluation Error: Resource type not found: Cron::Special (file: /etc/puppetlabs/code/modules/cron/manifests/job.pp, line: 30, column: 3)

Any additional information you'd like to impart

I have downgraded the module to 4.0.0 and the problem went away

Test and enable for Puppet 7

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7.0+
  • Ruby: as bundled with Puppet 7.5
  • Distribution: all (tested on RHEL 7.9)
  • Module version: 2.0.0

How to reproduce (e.g Puppet code you use)

(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

What are you seeing

Installation / upgrade fails.

What behaviour did you expect instead

Successful installation of / upgrade to the puppet-cron 2.0.0 or later

Output log

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

Any additional information you'd like to impart

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.

Please make a new release

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: all
  • Ruby: Ruby
  • Distribution: FreeBSD
  • Module version: 2.0.0

How to reproduce (e.g Puppet code you use)

cron::weekly:
  'reload_httpd_to_reload_certificates':
    command: '/usr/sbin/service apache24 graceful'

What are you seeing

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

Any additional information you'd like to impart

This has already been fixed in #86 , but remains as of yet, unreleased.

Add support for tilde (Randomization)

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7.27.0
  • Ruby:
  • Distribution: RHEL8
  • Module version: 2.0.0

How to reproduce (e.g Puppet code you use)

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.

What are you seeing

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

What behaviour did you expect instead

Accept the tilde

Compare with cron_core ?

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.

Jobs is an array of hashes

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

Support for Managing Anacron

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7+
  • Ruby:
  • Distribution: RedHat Based (RHEL, CentOS, AlmaLinux) 7+
  • Module version: 4.1.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.

Comma character in hour/minute parameters

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 2018.1.0
  • Module version: puppet-cron 1.2.0

How to reproduce (e.g Puppet code you use)

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/]
]

Management of /etc/crontab

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!

Allow multiple applications (profiles) to add users to cron.[allow|deny]

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.

Implement CIS Benchmark requirements

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.

Missing tags for last releases

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

pattern error Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Syntax error at '/' at /etc/puppetlabs/code/environments/ci/modules/cron/types/minute.pp:4:11 on node

How to reproduce (e.g Puppet code you use)

What are you seeing

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"

What behaviour did you expect instead

it should add cron

Output log

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

Commas in template are ignoring. How to use the enumeration?

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!

Special parameter is now set incorrectly with two @

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.

Fails on FreeBSD because gid 0 is wheel, not root

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 6.16.0
  • Ruby: 2.6.6p146
  • Distribution: FreeBSD 11.3
  • Module version: 2.0.0

How to reproduce (e.g Puppet code you use)

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',
}

What are you seeing

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

What behaviour did you expect instead

Successful run.

Any additional information you'd like to impart

FreeBSD gid 0 is wheel, not root.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.