> Does CFEngine provide tool to render a mustache template?

No, CFEngine doesn't have a standalone tool to render mustache. This online demo is a good place to quickly prototype a simple template and data set.

Another option is to use a stand-alone policy file.

Name the file whatever you like. It looks for json in a file named the same suffixed with .json, it looks for a mustache template named the same suffixed with .mustache, and it renders to a file named the same suffixed with .txt.

So if you name the file /tmp/standalone-mustache.cf it will look for =/tmp/standalone-mustache.cf.json=, =/tmp/standalone-mustache.cf.mustache=, and render /tmp/standalone-mustache.cf.txt.

 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637
  # Standalone policy file for prototyping mustache
  bundle agent main
        "datafile" string => "$(this.promise_filename).json";
        "template" string => "$(this.promise_filename).mustache";
        "target" string => "$(this.promise_filename).txt";

        "data" data => readjson( $(datafile), inf); 

          create => "true",
          handle => "render_target",
          template_method => "mustache",
          edit_template => "$(template)",
          template_data => @(data);

        "JSON data file missing. Looking for '$(datafile)'"
          if => not( fileexists( $(datafile) ));

        "Mustache template missing. Looking for '$(template)'"
          if => not( fileexists( $(template) ));

          printfile => cat( $(target) ),
          depends_on => { "render_target" };

  body printfile cat(file)
  # @brief Report the contents of a file
  # @param file The full path of the file to report
          file_to_print => "$(file)";
          number_of_lines => "inf";

Now test the policy:

  echo '{ "msg": "hello world" }' > 
  echo '{{{msg}}}' > /tmp/standalone-mustache.cf.mustache
  chmod 600 /tmp/standalone-mustache.cf
  cf-agent -KIf /tmp/standalone-mustache.cf

Results in this output:

    info: Created file '/tmp/standalone-mustache.cf.txt', mode 


    info: Updated rendering of '/tmp/standalone-mustache.cf.txt' 

from mustache template '/tmp/standalone-mustache.cf.mustache'

R: /tmp/standalone-mustache.cf.txt:
R: hello world