read_module_protocol

Table of Contents

Prototype: read_module_protocol(file_path)

Return type: boolean

Description: Interprets file_path as module protocol output.

This function is useful for reducing overhead by caching and then reading module protocol results from a file.

Arguments:

  • file_path: string, in the range: "?(/.*)

Example:

bundle agent cache_maintenance
{
    vars:
      "file"
        string => "$(this.promise_dirname)/cached_module";

  classes:
    "cache_refresh"
      if => not(fileexists("$(file)"));
    Min30_35::
      "cache_refresh";

  files:
    cache_refresh::
      "$(file)"
        create => "true",
        edit_template_string => "=my_variable=$(sys.date)",
        template_data => "{}",
        template_method => "inline_mustache";
}

bundle agent demo
{
    classes:
      "cache_was_read"
        if => read_module_protocol("$(cache_maintenance.file)");

    reports:
      cache_was_read::
        "Module cache was read!";
        "cached_module.my_variable = $(cached_module.my_variable)";
}


bundle agent __main__
{
  methods:
    "cache_maintenance"
      handle => "cache_maintenance_done";
    "demo"
      depends_on => { "cache_maintenance_done" };
}

This policy can be found in /var/cfengine/share/doc/examples/read_module_protocol.cf and downloaded directly from github.

See also: usemodule(), Module Protocol

History:

  • Introduced in 3.15.0