Forum: CFEngine Help
Subject: Regarding to templates automatic caching
Author: toddnni
Link to topic: https://cfengine.com/forum/read.php?3,24368,24368#msg-24368
Hi all,
I have noticed that templates automatic caching has been mentioned often
recently. Here is my solution, which I have been using for about an year.
# This promises that a file is expanded from a template. The template file is
# loaded from the servers. It is recommended to refer to a variables array
# $($(use_template.v)) in the template file. Array should be assigned
# like this variable string => "value".
# Defines global class fixclass when file is updated.
bundle agent use_template(file, servers, template_file, perms, fixclass, v) {
vars:
any::
"canonified_filename"
string => canonify("$(file).template");
"tmp_filename"
string => "$(sys.workdir)/local/$(canonified_filename)";
files:
any::
"$(tmp_filename)"
comment => "Promises to load the template file to a temporary file. Uses
secure transfer just in case",
copy_from => no_backup_scp(
"$(template_file)",
"@(servers)");
"$(file)"
create => "true",
perms => m("$(perms)"),
edit_defaults => empty,
edit_line => expand_template("$(tmp_filename)"),
classes => if_repaired("$(fixclass)");
}
The bundle should be simple, but maybe the variable v needs a simple usage
example
bundle agent mybunbdle{
vars:
any::
"var_list" string => "test";
methods:
any::
"template_test" usebundle => use_template(
"/tmp/test",
"@(g.servers)",
"$(g.masterfiles)/files/test",
"444", "test_repaired",
"mybundle.var_list");
}
and template file should contain $($(use_template.v))
If this v thing seems overly complicated, you may forget/remove it.
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine