Cfengine Goodies

To content | To menu | To search

Tuesday 26 March 2013

CFEngine 3 :: Groups definition from csv file

csv_file.pngYou can set groups definition in a csv file.

update.cf synchronizes csv files and the agent uses them to define contexts.

Example :

Continue reading...

Tuesday 12 March 2013

CFEngine 3 :: Call bundle variable in a csv file

csv_file.png

An example to call architecture bundle variable in a csv service file

CFEngine example :

Continue reading...

Tuesday 26 February 2013

CFEngine 3 :: From csv to service_catalog

engine.jpg When you have service catalog datas from #1, we can organize then to feed service with this bundle (first field is the name of the array in accordance with meta service definition constraints):

CFEngine code :

Continue reading...

Friday 15 February 2013

CFEngine 3 :: csv concatenation

If your service catalog datas are stored in csv files and depend on architecture contexts, you can use this concat function.

bundle agent function_meta(prefix,params)
{

  vars:

    any::
      # variables
      "$(prefix)confidx"       slist   => getindices("$(prefix)_vars.conf");
      "$(prefix)mainfile"      string  => "$(globals.dir_cache)/main/$(prefix)/config.csv";
      "$(prefix)archfile"      string  => "$(globals.dir_cache)/$(architectures_vars.architecture_name)/$(prefix)/config.csv";
      "$(prefix)concatfile"    string  => "$(globals.dir_cache)/main/$(prefix)/concat.csv";
      # readfile
      "$(prefix)len"           int     => readstringarrayidx("$(prefix)meta","$($(prefix)concatfile)","\s*#[^\n]*",";",99,999999);

    architecture_defined::
      "concatlist"    slist   => { "function_meta.$(prefix)mainfile", "function_meta.$(prefix)archfile" };

    !architecture_defined::
      "concatlist"    slist   => { "function_meta.$(prefix)mainfile" };

  files:

        "$($(prefix)mainfile)"
            create      => "true",
            copy_from => u_dcp("$(globals.resources_location)/main/$(prefix)/config.csv");

        "$($(prefix)archfile)"
            create      => "true",
            copy_from   => u_dcp("$(globals.resources_location)/$(architectures_vars.architecture_name)/$(prefix)/config.csv"),
            ifvarclass  => "architecture_defined";

        "$($(prefix)concatfile)"
            create        => "true",
            edit_defaults => empty,
            edit_line     => concatWith(@(this.concatlist));

  reports:

    verbose::
      "$(prefix)::$(this.bundle) csv file :: $(function_meta.$(prefix)concatfile)";
}

bundle edit_line concatWith(file)
{

  insert_lines:

    "$($(file))"
      insert_type    => "file_preserve_block",
      expand_scalars => "false";
}