Forum: CFEngine Help Subject: Re: CFEngine Help: Re: CFEngine Help: Re: "real" templates Author: sauer Link to topic: https://cfengine.com/forum/read.php?3,23837,23881#msg-23881
Marco Marongiu Wrote: ------------------------------------------------------- > > Define your header as a scalar, > > doable, but I don't like having either multi-line > scalars or super-long > scalars across one line (the header string in one > line and using > $(const.n)). I feel it impairs readability. It somewhat gets you back to a template, but you could use readfile and put the header in an external file. Or define the header's value in another bundle, and just import it into your main bundle by referencing the foreign variable. > > do your edits with the > > empty_file rule, and rebuild the file from the > > ground up. You don't > > even need a template for that. Most ntp > > configurations I'm aware of > > don't have any kind of order neccesary. > > that's true in this case, but most of the time > order matters in a config > file (think of an INI file for a very common > example, or ssh_config > stanzas). In those cases, you just define a position for each line, as needed. There's a specific example covering ini files in the solutions guide, but basically you have two ways to manage position. The first is select region, which limits your edits to a given position within the file. That particularly helps with files which have stanzas, like ini files or pretty much everything on AIX, for example. The other part to maintaining order is the location parameter in insert_lines, which lets you find the location in the file you want to edit, and then put your entry above or below that location. If you read that section, you'll see things that define whether you should select the first or last occurence of a pattern, etc. as well. You probably also want to become quite good with regular expressions if you'll be doing this much. ;) Something else I'd normally not mention, but which is worth noting since you've used Puppet: given the same inputs (including relevant system state), Cfengine should produce the same output every time it runs. This is subtly relevant if you're creating file contents without specifying order. If your policy works by emptying the file and then adding stuff back in, you shouldn't end up recreating the file on every run; it should be created the same way in memory every time, and Cfengine will not update the file on disk because it's the same as what it's assembled in memory. This differs from the way Puppet's ordering works, where objects with the same priority and no explicit dependencies are executed in semi-random order. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine