Forum: CFEngine Help
Subject: reasonable "list append" workaround?
Author: matt_garman
Link to topic: https://cfengine.com/forum/read.php?3,23935,23935#msg-23935

Hi, I'm just getting started with cfe3 (community edition v3.2.1 on CentOS 
5.7).  I'm basically inventing things for CFE to do, just to familiarize myself 
with the system before doing a massive deployment.

I quickly came up with a (contrived) situation where I needed the ability to 
conditionally append to a list.  A web search led me to this "Add function to 
extend list if element is not present" issue (#240).  So apparently I'm not the 
only one looking to do something like this.

My contrived example is this: create one or more files, depending on the class. 
 In my specific case, I am working with two servers, "redserver" and 
"blueserver".  Both servers are part of the class "utility_net"; redserver is 
also part of the class "dns_server"; blueserver is part of the class 
"backup_server".

Here's what I came up with:

bundle agent test2
{
    vars:
        backup_server::
            "backup_svr_file" string => "/tmp/test_backup_server";

        dns_server::
            "dns_svr_file"    string => "/tmp/test_dns_server";

        utility_net::
            "util_svr_file"   string => "/tmp/test_utility_net";

        redserver::
            "redserver_file"   string => "/tmp/test_redserver";

        blueserver::
            "blueserver_file" string => "/tmp/test_blueserver";

        any::
            "testfiles" slist => {
                ${backup_svr_file},
                ${dns_svr_file},
                ${util_svr_file},
                ${redserver_file},
                ${blueserver_file}
            };

    files:
        "${testfiles}" -> "Some Stakeholder"
            comment    => "Make sure file @{testfile} exis",
            create     => "true",
            edit_line  => append_if_no_line("${sys.host}");
}


I've been a programmer the last 10 years, so I'm struggling a bit to mentally 
"switch gears" to thinking about things in CFE's idiom.  The above works, I'm 
just wondering if it's the "best" way to accomplish what I'm after ("best" as 
in true to the CFE way of doing things).

Thanks!

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

Reply via email to