Soon after posting The right order in cfengine, I asked in the help list if it was the right way to do it. To discover that my approach was a bit too overkill 🙂
So, while still a bit overkill, the following could be a much better approach: …
body common control { bundlesequence => { "test" } ; inputs => { "cfengine_stdlib.cf" } ; version => "Slow convergence"; } body classes always(x) # Define a class no matter what the outcome of the promise is { promise_repaired => { "$(x)" }; promise_kept => { "$(x)" }; repair_failed => { "$(x)" }; repair_denied => { "$(x)" }; repair_timeout => { "$(x)" }; } bundle agent test { files: "/tmp/t2.txt" edit_defaults => empty, create => "true", edit_line => t2 ; } bundle edit_line t2 { vars: "index" slist => { "a", "b", "c", "d" } ; classes: "has_$(index)" expression => "trigger" ; insert_lines: any:: "### header ###" classes => always("trigger") ; trigger:: "this should be the second" classes => always("step_a") ; has_a.step_a:: "third" classes => always("step_b") ; has_b.step_b:: "fourth" classes => always("step_c") ; has_c.step_c:: "fifth" classes => always("step_d") ; has_d.step_d:: "last" ; }
As you can see, it's basically the same thing, but now all of the file editing takes place in a single files:
promise, with an edit_line
bundle that applies all the needed insert_lines
promises: much more logical.
I have to go now, and read the docs Mark Burgess posted. They look quite promising 🙂