Hi, in some cases I have to edit a file multiple times. I found that file changes every time although it contains the required lines. I'm quite sure I'm missing something very basic.
I've set up a small test file, please find it below. I run the latest RPM of community edition. cf-agent -V This comprises cf-agent core community version 3.0.4p1 - (C) Cfengine AS 2008- I have two questions: 1 - How to avoid to change the file every time? 2 - If I start with a file that have "#" lines the output will be like this: ############################ # This file maintained by CFengine. Don't modify it directly! ############################ # ... I'd expect the same header than starting with empty/no file. Why is this happening? Based on the doc this format should make sure I'll have my lines in the same order than starting with an empty file. Regards, Miklos TEST FILE: body common control { any:: bundlesequence => { example }; } bundle agent example { vars: # binlog "disk[mysql51_1][name]" string => "binlog"; "disk[mysql51_1][device]" string => "sdb"; "disk[mysql51_1][size]" string => "30G"; "disk[mysql51_1][user]" string => "mysql"; "disk[mysql51_1][group]" string => "mysql"; "disk[mysql51_1][mountoptions]" string => "ext3 defaults,noatime 0 2"; # mysql51 "disk[mysql51_2][name]" string => "mysql51"; "disk[mysql51_2][device]" string => "sdc"; "disk[mysql51_2][size]" string => "300G"; "disk[mysql51_2][user]" string => "mysql"; "disk[mysql51_2][group]" string => "mysql"; "disk[mysql51_2][mountoptions]" string => "ext3 defaults,noatime 0 2"; "index" slist => getindices("disk"); files: "/tmp/test.cfengine" comment => "Add mount points", edit_line => myedit("/dev/vg$(disk[$(index)][device])/$(disk[$(index)][name]) /vg/vg$(disk[$(index)][device])/lv$(disk[$(index)][name])/ $(disk[$(index)][mountoptions])",".*$(disk[$(index)][name]).*"), create => "true", classes => DefineIfChanged("fstab_has_changed"); reports: fstab_has_changed:: "File has changed"; } #*************************************************************************************************** bundle edit_line myedit(addline,delete) { vars: "initial_comment" string => "############################$(const.n)#$(const.n)# This file maintained by CFengine. Don't modify it directly!$(const.n)#$(const.n)############################" ; delete_lines: "$(delete)"; insert_lines: "$(addline)"; "$(initial_comment)" location => start; # Removed to reduce the noise #reports: # #linux:: # "Added lines: $(addline)"; } body classes DefineIfChanged(class) { promise_repaired => { "$(class)" }; } body location start { # If not line to match, applies to whole text body before_after => "before"; } _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine