CFEngine: little insert_lines annoyance fixed

Sometimes, crontab entries are preferable over CFEngine internal scheduling when jobs have special scheduling requirements. I have one example where a job must absolutely be started every 2 minutes. (03:20, 03:22, 03:24 and so on)

By default cf-execd is started every 5 minutes, it is ok for 03:20 with Min00, but Min22 and Min24 hard classes will never be defined while cf-execd is running, and some job occurrences never started. Cf-execd can be launched every minute, but by reducing this interval you may have to deal with lock issues. (long splaytime ?)

In such cases, an insert_lines promise to system crontab does the job, however insert_lines tries to give to regular expression metacharacters their special meaning, what is not desired:

body common control {
  bundlesequence => { "insert" };

bundle agent insert {

      comment   =>  "Insertion of lines containing special meaning characters",
      edit_line =>  my_insert;

bundle edit_line my_insert {

    "*/2 * * * * root /path/to/my/";

Running the bundle:

$ cf-agent -KIf
Running full policy integrity checks
Regular expression error "nothing to repeat" in expression "*/2 * * * * root /path/to/my/" at 0
-> Edit file /tmp/crontab

It works, but the “Regular expression error…” message is a bit annoying, especially with many files editing promises.

A solution is to avoid special meaning characters in the crontab entry:

0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,...(you get the idea) * * * * root /path/to/my/

Not only the line is unreadable but also error-prone. Warning message is gone but the gain is not obvious.

Fortunately, this has been fixed 14 days ago in core/master branch \o/

$ cf-agent -KIf
Running full policy integrity checks
-> Edit file /tmp/crontab

This will certainly be part of the CFEngine 3.5 release.