puppet-logrotate icon indicating copy to clipboard operation
puppet-logrotate copied to clipboard

rotate must be an integer

Open parhamr opened this issue 11 years ago • 17 comments

The parsing of rotate appears to differ from the official documentation. In the examples, rotate is presented as a Ruby Fixnum. In the code, the match criteria appears to only work for numeric characters from a Ruby String.

This is working for me:

  logrotate::rule { 'redis_6384':
    path          => '/var/log/redis_6384.log',
    rotate        => '4',
    mail          => '',
    rotate_every  => 'week'
  }

This block returns an error:

  logrotate::rule { 'redis_6384':
    path          => '/var/log/redis_6384.log',
    rotate        => 4,
    mail          => '',
    rotate_every  => 'week'
  }

==> data: Error: Logrotate::Rule[redis_6384]: rotate must be an integer on node db01.hostname.dev

Am I misunderstanding something? Is the documentation wrong? Is the parser incorrect?

Thanks!

parhamr avatar Oct 20 '14 21:10 parhamr

Just for clarity here - are you using the future parser? Getting the same thing right after changing over here. Puppet 3.7.3

CpuID avatar Nov 18 '14 06:11 CpuID

I am seeing this specifically with the entries in manifests/defaults/debian.pp, if I change the Logrotate::rule definition to use rotate => '1' instead of rotate => 1, it works fine.

CpuID avatar Nov 18 '14 06:11 CpuID

just a note - https://github.com/rodjek/puppet-logrotate/commit/d569bcee1b43fa1af816c21afb5664d8e5235553 fixes this issue. use master instead of 1.1.1, or @rodjek may be nice enough to arrange a version bump? :)

CpuID avatar Nov 18 '14 07:11 CpuID

+1 for this, I had to manually fix this. Please get this updated in forge, it would be appreciated.

Future parser stops being future Q1 2015 (aka soon).

jowrjowr avatar Dec 04 '14 02:12 jowrjowr

Hey, any progress here? could you bump the version to release the fix?

bastelfreak avatar Mar 24 '15 13:03 bastelfreak

Just ran into this. What is stopping this from progressing to a patch release?

p--b avatar Sep 21 '15 06:09 p--b

(Looking at it, wouldn't a better fix than those proposed be to just do case "${rotate}" { on :302?) The problem is that regex matches explicitly (according to the manual[0]) only match strings - so an integer (as demanded) will never match!

[0] - https://docs.puppetlabs.com/puppet/latest/reference/lang_conditional.html#case-matching

p--b avatar Sep 21 '15 06:09 p--b

Yes, this was with the future parser.

parhamr avatar Sep 21 '15 19:09 parhamr

What's stopping this from being released into the forge? I've just run into the same problem when I started using this module today (1.1.1 from the forge).

NoodlesNZ avatar Oct 08 '15 21:10 NoodlesNZ

Can I somehow avoid this error:

Evaluation Error: Error while evaluating a Function Call, Logrotate::Rule[wtmp]: rotate must be an integer at .../modules/logrotate/manifests/rule.pp:306:7

without using the "master". The wtmp 'Rule' is inside the logrotate module, so I do not know how to influence/overwrite it.

kontrafiktion avatar Oct 14 '15 08:10 kontrafiktion

Well, the maintainer really should fix their broken module.

Meanwhile, one hacky workaround:

Put the following in a file, say ~/logrotate.patch:

From 29bb3c2b64fd5c5ba718c1100d7f380b86637d13 Mon Sep 17 00:00:00 2001
From: Peter Bridgman <[email protected]>
Date: Mon, 21 Sep 2015 07:23:06 +0100
Subject: [PATCH] Fixes integer validation in Puppet 4

Case regex validation only succeeds on strings, which is somewhat
troublesome when using them to validate integers. By forcing any
passed integers to be strings, we cause integers to match the regex as
desired.
---
 manifests/rule.pp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/manifests/rule.pp b/manifests/rule.pp
index 22b5201..a8b7fe4 100644
--- a/manifests/rule.pp
+++ b/manifests/rule.pp
@@ -296,7 +296,7 @@
     }
   }

-  case $maxage {
+  case "${maxage}" {
     'undef': {}
     /^\d+$/: {}
     default: {
@@ -312,7 +312,7 @@
     }
   }

-  case $rotate {
+  case "${rotate}" {
     'undef': {}
     /^\d+$/: {}
     default: {
@@ -328,7 +328,7 @@
     }
   }

-  case $shredcycles {
+  case "${shredcycles}" {
     'undef': {}
     /^\d+$/: {}
     default: {
@@ -336,7 +336,7 @@
     }
   }

-  case $start {
+  case "${start}" {
     'undef': {}
     /^\d+$/: {}
     default: {

(SPOILER ALERT: this is just #62)

Then:

$ cd /etc/puppetlabs/code/environments/production/modules/logrotate
$ patch -i ~/logrotate.patch -p1

Yes, I know this is horrific. It also makes the problem go away for a bit.

p--b avatar Oct 14 '15 08:10 p--b

I'm having this too.

marcusphi avatar Oct 15 '15 13:10 marcusphi

I just asked Tim per EMail, if he still (wants to) maintain this repo

kontrafiktion avatar Oct 19 '15 08:10 kontrafiktion

Just ran into this as well. Any update on making a release?

hany avatar Dec 15 '15 01:12 hany

I also have this problem with v1.1.1 using the above patch works, but is not suitable for a production system.

steventwheeler avatar Dec 28 '15 19:12 steventwheeler

bump

jonhattan avatar Jul 27 '16 13:07 jonhattan

go with this fork, approved by puppet folks https://forge.puppet.com/yo61/logrotate

jonhattan avatar Jul 27 '16 13:07 jonhattan