Forum: CFEngine Help Subject: Re: About "new" templates correct usage or limitations Author: th Link to topic: https://cfengine.com/forum/read.php?3,26723,26793#msg-26793
I'll try to sum up what I want and the limitations I encounter : Let's say I have 2 types of hosts and I want to configure (OR INSTALL) some config file differently on each one. 1. edit_line cannot install or repair the whole file I could use edit_line/insert_line/delete lines with class expressions in my .cf file on just the lines I want to be different from the package supplied file -> if someone deletes the file, I cannot repair it -> so I thought of using some kind of template to be able to reconstruct the whole file. 2. [% CFEngine BEGIN/END %] blocks are meant for iteration and should be kept minimal I want to be able to keep duplicate lines (two white lines for instance), so (mis-)using the [ %CFEngine BEGIN/END %] "side effect" which is "each multi-line group maps to a multi-line insert_lines promise, with insert_type => preserve_block" might be an option. -> Mark explained that's not what those blocks are meant for. -> Besides, I don't need to iterate and anyway this (mis-)usage might cause a "Expansion overflow construction string" if the block is too large. 3. expand_template forces me to define all the variables for every classes So maybe expand_template with the template embedding some variables to be expanded is what I need ? -> what if in the config file, var1 must be defined for host1 but not on host2 ? my template file would state something like var1 = $(var1) but in my .cf file, if I write : host1:: "var1" string => "value" ; host2:: expand_template would generate var1 = $(var1) literraly on host2 -> You might say I still can define the default value of var1 on host2 : host2:: "var1" string => "" But what about config files (think make.conf en FreeBSD) who check only if the variable is defined, whatever its value (WITH_SASL=no -V PKGNAMESUFFIX would generate -sasl-server on FreeBSD for instance) ? Conclusion : My understanding is that : - the "template" term is misleading in the case of edit_template (this is by no way a complaint or criticism) - I still don't have what I'd need, which is expand_template (copy verbatim with duplicate lines and expand variables) WITH the [% CFEngine class:: %] tags mechanism Hope this clarifies... Thanks -- TH _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine