Before you get started on this, I think you should ask yourself this:

1) Do I want to maintain all of crontab (regardless of which machine gets what) 
with CFEngine, or
2) Do I want to maintain a PART of crontab with CFEngine (and handle machine 
differences manually on each machine)

Personally, I think 2 is a worse Idea, but if that's what you want, then using 
a clear start/end marker and then maintaing promises in that region with "body 
select_region" is how to do it.

However, I think having CFEngine maintain all of a file is often (but not 
always) better, and here is how I maintain ntp.conf on two different networks 
(the concept will match what you want to do - I am leaving out process 
restarting, etc):

bundle agent servers

{
vars:

    ipv4_10_0_1::
        "ntp_conf" string => "
peer    fit-pc.ibp.com.
server  0.us.pool.ntp.org       maxpoll 6
server  1.us.pool.ntp.org       maxpoll 6
server  2.us.pool.ntp.org       maxpoll 6
";

    ipv4_10_0_2::
        "ntp_conf" string => "server  fit-pc.ibp.com maxpoll 6 prefer";

files:
        "/etc/ntp.conf"
            create => "true",
            perms => mo("644", "root"),
            edit_line => ExpandMeFrom("$(sys.workdir)/clientfiles/ntp.conf", 
"$(ntp_conf)"),
            edit_defaults => empty;
}

bundle edit_line ExpandMeFrom(template, hs)
{
vars:
    "host_specific" string => "$(hs)";

insert_lines:

   # The variable $(host_specific) is in the $(template) file...
   "$(template)"
        insert_type     => "file",
        expand_scalars  => "true";
}


Then in $(sys.workdir)/clientfiles/ntp.conf I have:

#
# Do not edit - this file maintained by cfengine from 
$(bootstrap_g.policy_server)
#
server  clock-1.cs.cmu.edu      maxpoll 6
server  clock-2.cs.cmu.edu      maxpoll 6
$(host_specific)
pidfile /var/run/ntpd.pid
driftfile /etc/ntp.drift

Voila - CFEngine maintains the same file in different ways on different 
machines, but with a core of matched functionality.  You can even have multiple 
host-specific variables if you wanna go crazy.

-Dan


On Sep 13, 2011, at 11:56 AM, no-re...@cfengine.com wrote:

> Forum: CFEngine Help
> Subject: Re: inserting lines into crontab
> Author: davidlee
> Link to topic: https://cfengine.com/forum/read.php?3,23442,23447#msg-23447
> 
> Neil: Thanks for the reply, about defining a list in cfengine and appending 
> that.  There are two drawbacks for us, one technical, the other political:
> 
> Technically: while that handles adding the lines in the first place, it 
> doesn't address maintaining those same lines into the future (changing 
> details, deleting old entries) unless one writes even more cfengine 
> scripting.  (Or have I missed something?)
> 
> Politically: my team (to which I am still relatively new) is new to cfengine 
> and are worried about the relative difficulty and obscurity of it compared to 
> "well we simply used to copy files and it worked; why do we need this 
> cfengine stuff".  And although I personally like cfengine, I confess to 
> sympathising with them, even agreeing with them.  We're after a clear, simply 
> stated promise of "please maintain the contents of a common source 
> crontab-like file X into the target crontab file Y".  (Note also the "clear, 
> simply stated" there.)
> 
> Mike: re your "/etc/cron.d" suggestion: that looks very interesting.  (Smack 
> my own forehead "why didn't I think of that"!)  A promise that is clear and 
> simple to express.  Thanks.
> 
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to