behavior of `variablesmatching()`

24 views
Skip to first unread message

Riccardo Murri

unread,
Feb 27, 2015, 11:46:52 AM2/27/15
to help-c...@googlegroups.com
Hello,

has anyone tried to use the `variablesmatching()` function?
I am experimenting with it to use external templating engines [1],
but have run into troubles (see [2], [3]).

Are there any undocumented catches for using `variablesmatching()`?
For instance, it seems that namespace info is mangled and one must use
`#` instead of the colon character to separate namespace from the
variable name ...

[1]: https://gist.github.com/riccardomurri/bb3bd26406724f4193e6
[2]: https://dev.cfengine.com/issues/6991
[3]: https://dev.cfengine.com/issues/6990

Thanks for any suggestion!

Riccardo


Ted Zlatanov

unread,
Feb 27, 2015, 6:01:18 PM2/27/15
to help-c...@googlegroups.com
On Fri, 27 Feb 2015 16:46:37 +0000 (UTC) Riccardo Murri <riccard...@uzh.ch> wrote:

RM> has anyone tried to use the `variablesmatching()` function?
RM> I am experimenting with it to use external templating engines [1],
RM> but have run into troubles (see [2], [3]).

RM> Are there any undocumented catches for using `variablesmatching()`?
RM> For instance, it seems that namespace info is mangled and one must use
RM> `#` instead of the colon character to separate namespace from the
RM> variable name ...

RM> [1]: https://gist.github.com/riccardomurri/bb3bd26406724f4193e6

If I understand your example correctly, you're actually looking for the
datastate() function, new in 3.6:
https://docs.cfengine.com/docs/master/reference-functions-datastate.html

Once you have the data state captured, you can extract pieces of it[1] or
serialize the whole thing. Unfortunately until 3.7 you won't have the
new Mustache escape sequence to serialize a large data container (see
https://github.com/cfengine/core/pull/2031) so you'll be limited to 4K
on the serialized version of the data state. But do you *really* need
all of it? My guess is no.

If you must have absolutely all the data, you can generate some kind of
K=V format file in Mustache but it's not trivial.

Ted

[1] extract everything under key1 to a new container:

"subcontainer" data => mergedata("bigcontainer[key1]");


Riccardo Murri

unread,
Mar 3, 2015, 10:40:58 AM3/3/15
to help-c...@googlegroups.com
Hi Ted,

> If I understand your example correctly, you're actually looking for the
> datastate() function, new in 3.6:
> https://docs.cfengine.com/docs/master/reference-functions-datastate.html

Many thanks for the tip! Indeed `datastate()` plus some messing with
lists did the trick:

https://gist.github.com/riccardomurri/bb3bd26406724f4193e6#file-preprocess-cf

> Once you have the data state captured, you can extract pieces of it[1] or
> serialize the whole thing. Unfortunately until 3.7 you won't have the
> new Mustache escape sequence to serialize a large data container (see
> https://github.com/cfengine/core/pull/2031) so you'll be limited to 4K
> on the serialized version of the data state. But do you *really* need
> all of it? My guess is no.

Of course I would only need a subset for a specific template, but
having to list every variable used in the template in `.cf` files is
tedious and error-prone. Therefore I've tried to just export anything
that seems useful.


> If you must have absolutely all the data, you can generate some kind of
> K=V format file in Mustache but it's not trivial.

Well, the whole point of this exercise was to avoid using Mustache altogether...

Thanks,
Riccardo


Reply all
Reply to author
Forward
0 new messages