What ideas do others have on Best Practice for using lineinfile?
As a potential conversation starter, here's a couple of ideas that have recently gelled for me:
1) Use two rules:
* First delete all versions of the line
* Then add the finished version of the line.
This makes the process more idempotent (which, granted lineinfile has inherent problems with....)
For context, this idea gells around adding a mailrelay statement for postfix's
main.cf. In my environment I have 4 different platforms with various ad-hoc maintenance (covering quite a few years).
2) Use a (trailing) comment header (i.e. a "here are our changes" line) and then append changes after this.
Some more context here, I suspect lineinfile appeals to those of us who have an existing set of servers that we are incrementally bringing into line. The "correct" path is likely to use a template of a file, but that requires determining which of the (our various) distro's is the "correct" set of settings. For something like "use our mail relay" this is a fairly large hurdle.
Thanks for any comments in advance :-)