Here's a simpler case that also doesn't work the way that the insert_select feature intuitively sounds like it should work. The following example inserts all three lines in the created file, not just the two that would be inserted if the insert_if_match_from_list restricted insertions to lines that begin with "b".
bundle agent test { files: "/tmp/foo" create => "true", edit_line => blah; } bundle edit_line blah { vars: "lines" slist => { "foo", "bar", "baz" }; delete_lines: ".*"; insert_lines: "$(lines)" insert_select => begins_with_b; } body insert_select begins_with_b { insert_if_match_from_list => { "b.*" }; } Does anyone else make use of insert_select and can help understand how to use it? Thanks, Justin -----Original Message----- From: Justin Lloyd Sent: Friday, March 12, 2010 10:28 AM To: help-cfengine@cfengine.org Subject: RE: splitting a "blank" line Can someone tell me if I'm missing something? I noticed that I could try to prevent lines from being added with no netgroup name by using an insert_select body with the insert_if_match_from_list parameter. However, the documentation regarding this and related parameters is very confusing: http://www.cfengine.org/manuals/cf3-reference.html#insert_005fselect-in- insert_005flines insert_if_match_from_list: "Insert line if it fully matches a regex in the list" "The list contains regular expressions to search for in an secondary file (not the main file being edited). If the regex matches a complete line of the file, that line from the secondary file will be inserted at the present location in the primary file." What secondary file?! I'm wondering if that's just out-of-date documentation. I thought I could just do something like this: bundle edit_line enforce_passwd_netgroups(valid_netgroups) { vars: "netgroups" slist => { @(valid_netgroups) }; delete_lines: "\...@.*"; insert_lines: "+...@$(netgroups):x:::::" insert_select => ignore_blank_values; } body insert_select ignore_blank_values { insert_if_match_from_list => { "+...@[a-z].*" }; } That didn't work and upon closer reading I got confused by the talk of a secondary file, but with no explanation of where that file would even be specified. It just doesn't make sense. Can anyone help me understand this? (Yes, this is a hack because I can't figure out how to otherwise deal with blank results from my execresult() call.) Thanks, Justin -----Original Message----- From: help-cfengine-boun...@cfengine.org [mailto:help-cfengine-boun...@cfengine.org] On Behalf Of Justin Lloyd Sent: Thursday, March 11, 2010 7:01 PM To: help-cfengine@cfengine.org Subject: splitting a "blank" line I want to do the following (unimportant details omitted) and so far I'm stumped: bundle agent test { vars: "output" string => execresult("somecommand", "noshell"); "netgroups" slist => splitstring("$(output)", "\s+", 20); files: "/etc/passwd" edit_line => enforce_netgroups("@(this.netgroups)"); } bundle edit_line enforce_netgroups(netgroups) { delete_lines: "\...@.*"; insert_lines: "+...@$(netgroups):x:::::"; } The problem is when "somecommand" returns a blank line, so $(output) contains a single newline. Thus I end up with the single netgroup line +@:x::::: in my passwd file. It can be legitimate for the command to return a blank line, meaning there are no allowed netgroups for a given host (maybe it's not an ldap client; I will have a separate ldap_client class later, but that's kinda beside the point for this exercise). I've also tried using regline() in lots of ways to determine if the line is blank, but I wasn't getting that to work. Having a Perl-like chomp() feature might help. :) So how do I detect it's a "blank" line, despite the newline, so that I can prevent any lines from being inserted into the passwd file? Note that I *do* want the files promise to occur since there may be invalid netgroups for it to delete. Thanks, Justin -- Justin C. Lloyd Unix Infrastructure Engineer DigitalGlobe, An Imaging and Information Company This electronic communication and any attachments may contain confidential and proprietary information of DigitalGlobe, Inc. If you are not the intended recipient, or an agent or employee responsible for delivering this communication to the intended recipient, or if you have received this communication in error, please do not print, copy, retransmit, disseminate or otherwise use the information. Please indicate to the sender that you have received this communication in error, and delete the copy you received. DigitalGlobe reserves the right to monitor any electronic communication sent or received by its employees, agents or representatives. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine