Just want to say that I am very sorry that I have not yet had time to reply properly to the original mail, but glad that you have received more help from other sources. I still have it on my to-do list to review this thread, and hope to do so soon.

best
Mark

On 11/04/2011 01:04 PM, Marco Marongiu wrote:
Hi all

I started the thread «"real" templates» because I was looking for a nice
way to create my ntp.conf files for NTP unicast/multicast
clients/servers, and I was a bit frustrated at how little smart
templates are in cfengine.

I would like to thank all those who tried to help me.

Using the tips I got from the ML, I was able to get a working
configuration, but I kept researching because 1) I didn't like the
concat/join chicanery I was forced to use; 2) I didn't like to have a
huge amount of information in a single ntp bundle; 3) I didn't like the
idea of multi-line strings into the policy --which, IMO, impairs clarity.

Yet, the final version of my policy is again based on a template and a
huge bundle. You will find a sample in attachment. The cf file is pulled
in from promises.cf, and the "ntp" bundle added to the bundlesequence,
when the ntp class is defined (I am using Neil Watson's technique here
(http://tinyurl.com/6jekxzz)).

I still find annoying that, in order to remove a variable reference from
the resulting file, I have to insert a spurious comment (or a spurious
blank line, which is even worse). That's the price I had to pay to place
things exactly where I wanted.

Below you'll find a summary of the approaches I tried and why I ditched
them.


= single edit_line bundle =

I found it nice that I didn't have to do any chicanery to add one
"server $(server) iburst" line for each element of @server. But I got
frustrated by a few facts:

- it's damn too hard to place each single block of text where you want
it, they way you want it, especially if you don't like to rely on
markers or placeholders

- if you start writing lines to the file, one by one, using a promise
for each one, you'll find that you are not able to place two identical
lines in the file (e.g. two lines barely containing a "#" to separate
two sections in an header), unless you go through some "location =>"
alchemy.


= single edit_line bundle, plus methods =

This was nice because I could confine different pieces of information in
smaller, manageable bundles, and try to call each bundle conditionally
and in a certain order.

That actually proved much harder than it seemed at first, and was
plagued by class/variable scoping issues. In order to address them, I
would have to pass about a dozen variables to the called bundles, and
then pass them again from the agent bundle to the edit_line bundle in
the final stage.

In the end, I was trading in clarity to get smaller bundles... at which
point I gave up this approach.


= many edit_line bundles, and methods =

If the previous approach was a clarity killer, then what about this? I
gave up at the design stage, without even writing a single line.


= final remarks =

Creating configuration files is something that we do all the time, and
cfengine is one of the tools that should help us to do it efficiently.

Specifying that a number of groups of text lines should conditionally go
into a file in a well defined order is not that uncommon, and is
something one would expect to be an easy task. Yet, doing it with
cfengine has proved not that easy, especially if you don't want to rely
on artefacts like markers or placeholders. And I am still to try and
create an ssh_config file, where using a template is out of business...

I have used Perl a lot, and the rule "easy things should be easy" is
bundled in my DNA now. Having an hard time to do easy things like
editing a simple config file won't probably discourage me to use
cfengine, but that doesn't mean I am happy with that...


Ciao
-- bronto


_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to