At SURFsara we have developed a general library to generate files from templates. In our setup we can easily specify the default values and override them in other json file(s) or via def.cf/json. The goal is to set up an global repository for mustache templates.
For all senarios the mustache/json file(s) will be copied to the local node directory:
- The json and template file(s) are copied from the policy hub:
templates/$(bundle_name)
- The copies are placed in:
$(def.node_template_dir)/$(bundle_name)
- The following json must always be present and will always be copied: default.json
- Extra json file(s) can be specified in def.cf/json:
$(bundle_name)_json_files
- Scripts can generate json file(s) on a host/node. The json file must be copied into:
$(def.node_template_dir)/$(bundle_name)
- The generated file(s) are specified in def.cf/json:
$(bundle_name)_local_generated_json_files
- You can override values via def.json, Note: This one always wins.
Both senarios will be described in the subsection below. For both senarios you can specifiy multiple json files. The files will be merged and the last one wins if the same variable name is used,eg:
- a.json defines:
a : 1
- b.json defines:
a : 2
If the order is { "b.json", "a.json" }
the value of a would be 1
For now some copy actions are required. I will make an autotools setup. there are two options
- Include it in the Master Policy Framework (MPF)
- Include it in your own framework
The def.node_template_dir
variable is set in lib/surfsara/def.cf
, but can also be set
set in def.json
. The def.json wins, eg:
vars:
{
"node_template_dir" : "/etc/node_status/templates"
}
For older versions you have to manually add the shorcut templates
to controls/cf_serverd.cf
"$(sys.workdir)/templates"
handle => "server_access_grant_access_templates",
shortcut => "templates",
comment => "Grant access to templates directory",
admit => { @(def.acl) };
- Login on your policy server.
- Copy the contents of masterfiles into your masterfiles or equivalent repository
- Copy the
examples/templates
directory to$(sys.workdir)/templates
:cp -a examples/templates $(sys.workdir)/templates
- Enable autorun, if you have not done it, by adding this class to your
def.json
file
{
"classes" :
{
"services_autorun" : "any"
}
}
- Login on your policy server.
- cp -a masterfiles/lib/surfsara
<masterfiles>/lib/surfsara
- cp -a examples/templates $(sys.workdir)/templates
- include
/lib/surfsara/stdlib.cf
in your inputs
body common control
{
inputs => {
...
"lib/surfsara/stdlib.cf",
...
};
}
See above to add templates shortcut
to cf-serverd.
There are several template setups for different services included with inline documentation. These setups are used in prodduction at SURFsara.
- examples/services/autorun/ntp.cf
- examples/services/autorun/postfix.cf
- examples/services/autorun/resolv.cf
- examples/services/autorun/tcpwrappers.cf
- examples/services/autorun/sara_user_consume_resources.cf
- examples/services/autorun/singularity.cf
- examples/services/autorun/ssh.cf
- examples/services/autorun/tripwire.cf
- examples/services/autorun/yum.cf
To enable the template on your system:
- MPF: copy a setup to the
masterfiles/services/autorun
directory - Own Framework:
- copy a setup to your masterfiles directory
- add the files to your
inputs
statement - Activate the bundle
- Via the meta tags:
- autorun
template_<bundle_name>
, eg: bundle_ntp
- usebundle:
- ntp_autorun()
- tcpwrappers_autorun()
- Via the meta tags:
In this file you can override settings for the templates. When the json data is merged. This one wins, eg:
"vars": {
"ntp" : {
"server": [ "<your_ip_server1>", "<your_ip_server2>" ]
}
}
You can also specify a json setup file:
"vars": {
"tcpwrapper_json_files": [ "allow_ssh.json", "allow_http.json" ]
}
You can also override settings in this file, eg:
- One variable:
vars:
"ntp" data => parsejson( '{ "server" : [ "<your_ip_server1>" ] }' );
- json file:
vars:
"tcpwrapper_json_files" slist => { "allow_ssh.json", "allow_http.json" };
"tripwire_json_files" slist => { "systemd.json" };
IF you definied your own def.cf
and do want to use the one include in this framework you can set the following class:
SURFSARA_SKIP_DEF_CF_INCLUDE
The SURFsara CFEngine library also checks for some classes:
- The copy of the json/mustache file(s) can be skipped by
-DMUSTACHE_SKIP_COPY
. So you can change the files localy for testing. - To debug the mustache setup:
-DDEBUG_MUSTACHE
(all service bundles) - To debug mustache for a service bundle, eg
-DDEBUG_ntp