Bug #2127

cron resource adds newline when compiled from a template

Added by Phil Schwartz about 3 years ago. Updated 11 months ago.

Status:Rejected Start date:04/01/2009
Priority:Low Due date:
Assignee:- % Done:

0%

Category:cron
Target version:-
Affected Puppet version:0.24.7 Branch:
Keywords:
Votes: 0

Description

If the template consists of a single line that does not end with a templated variable or ruby code snippet then a newline is added to the cron command. This causes an issue when puppet reapplies it’s configuration since it always compares “cmd” with “cmd\n” and thus recreates the crontab each time it runs.

if template contains “/bin/true” then a newline is appended. However, if the template ends with a –%> then the newline is suppressed, so the following workaround suffices “/bin/true <% ”“ –%>. This hack isn’t elegant nor obvious, but it appears to work.

History

Updated by Luke Kanies about 3 years ago

  • Status changed from Unreviewed to Rejected

There isn’t much Puppet can do about this – it’s not going to know when you want the newline from your template and when you don’t. The only possible option is that you maintain the template so that it produces exactly what you want; in this case, that means finding a way to remove the newline.

Updated by Phil Schwartz about 3 years ago

Then I’m not sure why when puppet compares the entry in the crontab (that it previously inserted) and the current template result why it considers them to be different. If puppet produced the prior crontab and the new crontab why wouldn’t they be identical? That is, either they both should have a newline or they both shouldn’t. The current implementation is that one does and one doesn’t which appears to be a bug.

Updated by Luke Kanies about 3 years ago

  • Status changed from Rejected to Needs More Information

Ah; I think I misunderstood. You’re saying that Puppet is maybe stripping the newline when it writes the cron command to disk, but isn’t stripping it when it compares them?

I can’t find anywhere in the cron type or provider that explicitly remove newlines, so this would be a bit weird.

Updated by Phil Schwartz about 3 years ago

For a template, true.erb:

$ cat true.erb /bin/true

$ wc -l true.erb 1 # no additional newlines

Puppetd logs a message:

command changed ‘/bin/true’ to ‘/bin/true ’

notice the last single-quote (‘) is on the next line so puppet is comparing “/bin/true” to “/bin/true\n”. I logged the \n as the problem (since stripping it off in the template with <% “” –%> works around the issue). However, the problem could be that the existing crontab entry doesn’t contain the newline, such that puppet should be comparing “/bin/true\n” with “/bin/true\n”.

The main point here is the fact that the crontab that puppet creates (has newline) differs from the way puppet retrieves (no newline) it for comparison purposes.

Updated by Luke Kanies about 3 years ago

  • Status changed from Needs More Information to Accepted
  • Target version set to 2.6.0

I think I see what’s happening: Puppet is writing your new line out, but when it parses the crontab, it splits on newline, so it effectively removes the newline.

I guess this is a bug, since it should strip the new line, but… your input is broken, and the workaround is trivial.

Updated by Luke Kanies over 2 years ago

  • Priority changed from Normal to Low

Updated by James Turnbull over 2 years ago

  • Target version changed from 2.6.0 to 2.7.x

Updated by Nigel Kersten about 1 year ago

  • Status changed from Accepted to Rejected

We have more serious issues with the cron provider, and given the existence of a simple workaround, I’m going to be somewhat heartless and reject this one.

Updated by James Turnbull 11 months ago

  • Target version deleted (2.7.x)

Also available in: Atom PDF