I am playing with mustache and have a question about how to access the data variable in mustache. There is a code about keys and values, see below.
What i want is to access the value for a key, eg:
* vars.sara_mustache_expand_file.ldata[acl_internal_clients_management]
How can I accomplish this in the mustache language?
The following pseudo code how list key/value pairs:
bundle agent sara_mustache_expand_file(bundle_name, template_data, source, target)
{
vars:
"template_dir" string => "$(g.node_status)/templates/$(bundle_name)";
"ldata" data => @(template_data);
files:
"$(target)"
comment => "Expand the template to a temporary location to prevent zero files",
create => "true",
edit_template => "$(template_dir)/$(source)",
template_method => "mustache",
classes => sara_if_repaired( "template_expanded_$(source)", "template_$(source)" );
}
Now I can use this code for template generation:
==== template.mustache
<h1>{{vars.sara_mustache_expand_file.template_dir}}</h1
// ACL - internal clients management network allowed to query Bas
acl "internal_clients_management" {
{{#vars.sara_mustache_expand_file.ldata}}
{{@}} : {{%.}};
{{/vars.sara_mustache_expand_file.ldata}}
};
=====
This is the output of the generated file:
<h1>/etc/node_status/templates/bind</h1
// ACL - internal clients management network allowed to query Bas
acl "internal_clients_management" {
acl_internal_clients_management : [
{
"ip": "145.100.12.242"
}
];
acl_internal_masters : [
{
"ip": "145.100.29.50"
}
];
---
Bas van der Vlies
| Operations, Support & Development | SURFsara | Science Park 140 | 1098 XG Amsterdam
| T
+31 (0) 20 800 1300 |
bas.van...@surfsara.nl |
www.surfsara.nl |