Forum: Cfengine Help Subject: Strange behaviour with insert_lines Author: babudro Link to topic: https://cfengine.com/forum/read.php?3,18780,18780#msg-18780
I'm baffled by a behaviour of insert_lines that I just came across. Has anyone else run into this or can someone explain the rationale? If my insert_lines block looks like this: bundle edit_line ntp_rewrite { insert_lines: "# NTP (time) configuration"; "#"; "# This file is maintained by Cfengine."; "# Changes will be defenstrated."; "#"; "# This configuration is for a server w/out VMware."; "# VMware has its own NTP facility."; "#"; "restrict default kod nomodify notrap nopeer noquery"; (&c.) ...then the end result is this: # NTP (time) configuration # # This file is maintained by Cfengine. # Changes will be defenestrated. # This configuration is for a server WITHOUT VMware. # VMware has its own NTP facility. restrict default kod nomodify notrap nopeer noquery (&c.) Notice the missing 2nd and 3rd blank comment lines are present for readability. I try adding a space after the last hash-mark like so: insert_lines: "# NTP (time) configuration"; "#"; "# This file is maintained by Cfengine."; "# Changes will be defenstrated."; "#"; "# This configuration is for a server WITHOUT VMware."; "# VMware has its own NTP facility."; "# "; "restrict default kod nomodify notrap nopeer noquery"; (&c.) ... run cf-agent -IKb and I get this: # NTP (time) configuration # # This file is maintained by Cfengine. # Changes will be defenestrated. # This configuration is for a server WITHOUT VMware. # VMware has its own NTP facility. # restrict default kod nomodify notrap nopeer noquery (&c.) Now add in a space after the second lone hash-mark, i.e.: insert_lines: "# NTP (time) configuration"; "#"; "# This file is maintained by Cfengine."; "# Changes will be defenestrated."; "# "; "# This configuration is for a server WITHOUT VMware."; "# VMware has its own NTP facility."; "# "; "restrict default kod nomodify notrap nopeer noquery"; (&c.) ... and now I lost the 3rd one! # NTP (time) configuration # # This file is maintained by Cfengine. # Changes will be defenestrated. # # This configuration is for a server WITHOUT VMware. # VMware has its own NTP facility. restrict default kod nomodify notrap nopeer noquery (&c.) Finally, I add a space after the top hash-mark, so that all three solo hash-marks become hash+space "# ", and I am back to square one as if I had removed the space from them all: # NTP (time) configuration # # This file is maintained by Cfengine. # Changes will be defenestrated. # This configuration is for a server WITHOUT VMware. # VMware has its own NTP facility. restrict default kod nomodify notrap nopeer noquery (&c.) But if I place the comments in one large quoted-string, like this: insert_lines: "# NTP (time) configuration # # This file is maintained by Cfengine. # Changes will be defenestrated. # # This configuration is for a server WITHOUT VMware. # VMware has its own NTP facility. #"; "restrict default kod nomodify notrap nopeer noquery"; "restrict -6 default kod nomodify notrap nopeer noquery"; (&c.) ... I get the output I want: # NTP (time) configuration # # This file is maintained by Cfengine. # Changes will be defenestrated. # # This configuration is for a server WITHOUT VMware. # VMware has its own NTP facility. # restrict default kod nomodify notrap nopeer noquery (&c.) Thinking it might be a regex pattern bug, I tried using "?#" instead of a hash-mark alone, and also tried "#.", but got no change. Then I tried "#foo" and "# foo" and was astonished to get the same result. Surely "foo" is not regex... eureka! -- could it be that whatever I put in the first comment line is being ignored when it finds a matching line lower down? I tried this: bundle edit_line ntp_rewrite { insert_lines: "# NTP (time) configuration"; "# Mary had a little lamb."; "# This file is maintained by Cfengine."; "# Changes will be defenestrated."; "# Mary had a little lamb."; "# This configuration is for a server WITHOUT VMware."; "# VMware has its own NTP facility."; "# Mary had a little lamb."; "restrict default kod nomodify notrap nopeer noquery"; (&c.) ... and, yes, the 2nd and 3rd ones are missing in the output. Is this a bug or a feature I am not understanding? If it's a feature, I would appreciate if someone could give some insight on its application. BTW, this behaviour has been verified on both 32-bit and 64-bit machines, in both 3.0.5p1 and 3.1.0b2. Thanks! _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine