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

Reply via email to