bofh...@gmail.com writes:
> I have the following promise/mustache using community-3.10.0. The output
> in the reports section is correct but why won't the mustache file render
> correctly? If I put var "b" in the mustache file everything is OK but if I
> try to use the cmerge variable I don't get anything. What I am doing wrong?
Hi,
bundle agent cmerge creates a data container (you can easily dump the
multiline json representation for a datacontainer using {{%VARNAME}}. I
shuffled the policy a bit but noteably in your original mustache
template you were trying to access the cmerge data from the run bundle.
cmerge is it's own bundle so you need to access its vars directly
(vars.cmerge.NAME
). Also note,
variablesmatching_as_data()
Is a function that collects an merges data in a similar way.
Here is a working version of your example:
# DATASTATE #### # Works with just b {{#vars.init.b}} num={{num}} host={{host}} {{/vars.init.b}} # How does cmerge work? # Bundle agent cmerge creates a data container: {{%vars.cmerge.list}} {{#vars.cmerge.list}} num={{{num}}} host={{{host}}} {{/vars.cmerge.list}}
bundle agent main { methods: "init"; "check"; } bundle agent init
{ vars: "a" data => '[ { "num": "1", "host": "host1" } ]', meta => { "mymerge" }; "b" data => '[ { "num": "2", "host": "host2" }, { "num": "3", "host": "host3" } ]', meta => { "mymerge" }; "c" data => '[ { "num": "4", "host": "host4" }, { "num": "5", "host": "host5" } ]', meta => { "mymerge" }; "my_hosts" slist => variablesmatching(".*", "mymerge"); "merged" string => format("%S", "cmerge.list"); methods: "go" usebundle => cmerge( "list", @(my_hosts) ); }
bundle agent check { reports: "cmerge.list_str = $(cmerge.list_str)";
files: "/tmp/run.txt" create => "true", edit_template => "/tmp/run.mustache", template_method => "mustache"
; reports: "Content of /tmp/run.txt" printfile => cat("/tmp/run.txt"); }
I hope this helps!
–
Nick Anderson
Doer of things, CFEngine
"b" data => '[ { "num": "2", "host": "host2" }, { "num": "3", "host": "host3" } ]', meta => { "mymerge" };
I know that I am running this promise on host2 (or host3) how do I get num=2 (or num=3) respectively?
Thank you in advance,
Robin