bundle agent tester_test
{
vars:
"s_conf" string => "/usr/local/etc/tester.mustache";
"s_json" string => "/usr/local/etc/tester.json";
# Read in JSON file, then assign array of values to
# a promise slist
"s_data" data => readjson("$(s_json)", 50000);
"s_names" slist => getvalues("s_data[servernames]");
files:
# Read in JSON file for use in Mustache template
"/tmp/tester.rendered"
handle => "xx_render_mustache",
create => "true",
perms => mog("644","root","root"),
template_method => "mustache",
edit_template => "$(s_conf)",
template_data => readjson("$(s_json)", 50000),
classes => if_repaired("xx_fixed_tester");
commands:
# Using a class + depends_on ensures that this command
# only runs after the Mustache template is successfully
# rendered
xx_fixed_tester::
"/bin/touch /tmp/tester.ran-command"
depends_on => { "xx_render_mustache" };
reports:
# Report the slist read in from JSON
"$(s_names)";
}
{
"nodejsapps": [
{
"name": "sales",
"port": 3110
},
{
"name": "shipping",
"port": 3116
},
{
"name": "inventory",
"port": 3115
}
],
"servernames": [
"trivia",
"lofn",
"victoria",
"nesoi"
],
"trivia": [
{
"pythonapps": [
{
"name": "sales",
"port": 8110
},
{
"name": "shipping",
"port": 8116
},
{
"name": "inventory",
"port": 8115
}
]
}
]
}
This template demos the use of JSON values / arrays.
For more on Mustache, read the mustache(5) manpages
and the CFEngine documentation on template_method => "mustache"
-- array multi-value expansion (start) --
{{#nodejsapps}}
{{name}}:{{port}}
{{/nodejsapps}}
-- array multi-value expansion (end) --
-- nested array expansion (start) --
{{#trivia}}
{{#pythonapps}}
{{name}}
{{/pythonapps}}
{{/trivia}}
-- nested array expansion (end) --
And that is that.
On Thu, Feb 04, 2016 at 03:46:42PM -0800, Erik S wrote:
> where input data can be tweaked to affect the system-state outcome
> rather than modifying a promise file, syntax-checking it, committing it
> to git, etc. In other words, a mature promise ruleset can remain static
> and input data can be modified to meet changing system needs.
Have you seen EFL? :)
https://github.com/evolvethinking/evolve_cfengine_freelib
template_data => "$(s_data)",