Forum: Cfengine Help
Subject: Re: Inserting not at the end of line
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,19053,19054#msg-19054

Well, this seems to be a bug. When there is exactly _one_ line before the 
marker, I get the new line added three times to the end of the file. If there 
are no lines other than the marker, or more than one, then it behaves 
correctly. Below is a simplified self-contained snippet that shows the problem:

body common control
{
  bundlesequence => { "users" };
}


bundle agent users {
files:
  "/tmp/passwd"
  edit_line => append_before_netgroup,
  create => "false";
}

bundle edit_line append_before_netgroup {
insert_lines:
  "testuser:x:1001:1001::/home/testuser:/bin/bash"
  location => before_netgroup;
}

body location before_netgroup
{
  before_after => "before";
  first_last => "first";
  select_line_matching => "\+.*";
}

If /tmp/passwd contains the following:

blah:x:1000:1000::/home/blah:/bin/bash
+...@hostname:x:::::

Then the end result is like this:

blah:x:1000:1000::/home/blah:/bin/bash
+...@hostname:x:::::
testuser:x:1001:1001::/home/testuser:/bin/bash
testuser:x:1001:1001::/home/testuser:/bin/bash
testuser:x:1001:1001::/home/testuser:/bin/bash

If there is more than one "blah" line, then the result is as expected:

blah:x:1000:1000::/home/blah:/bin/bash
blah:x:1000:1000::/home/blah:/bin/bash
testuser:x:1001:1001::/home/testuser:/bin/bash
+...@hostname:x:::::


This is with 3.1.0b2 running under cygwin.

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to