Re: howt to access values in data container
Martin Simons <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Xander,
You might consider to look at this policy:
https://github.com/Webhuis/CFEngine-Roadshow/blob/opennebula-hnc/roadshow_policies/components/mnmutl_data.cf
It puts json into a container and then retrieves the data, bit by bit.
Regards,
Martin.
Op maandag 11 oktober 2021 om 15:39:30 UTC+2 schreef Xander Cage:
> hi,
>
> I tried various functions but its just frustrating...
>
> users.csv
>
> ClassExpression,uid,name,group,ssh_key
> weirdos,mscott,Michael
> Scott,pathetic,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg
> weirdos,jkras,John
> Krasinski,pathetic,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg
> twats,tflen,Toby
> Flenderson,tedious,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg
> zombie,fired,Get
> OUT!,buzzoff,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg
>
> test promise:
>
> bundle agent parent_bundle
> {
> classes:
>
> "weirdos";
> "twats";
> "zombie";
>
> vars:
> "data_file" string => "users.csv";
> "d" data => classfiltercsv($(data_file), "true", 0);
>
> "parameter_name" slist => getindices("d");
> "parameter_name_sorted" slist => sort(parameter_name, lex);
>
> "cvalues" slist => getvalues("d");
> "cvalues_sorted" slist => sort(cvalues, lex);
>
> "raw" data => @(d);
>
> methods:
>
> "call_remove" usebundle => child_bundle("$(this.bundle).d"),
> handle => "dba_user_guard",
> classes => results("bundle",
> "itsv_DABA_USER_NOT_JUSTIFIED");
>
>
> reports:
>
> "All users in parent function: data: $(with)" with =>
> string_mustache("{{%-top-}}", d);
>
> "Bonkers index is number instead of key name: Key: $(parameter_name)
> -> Value: $(cvalues)";
>
> "Totally useless for practical usage: $(d[0])";
>
>
> }
>
> bundle agent child_bundle (info) {
>
> vars:
>
>
> "user_crap1" slist => getindices("$(info)");
>
> "bla" data => mergedata("info");
> "user_crap2" slist => getindices("$(bla)");
>
> "user_crap3" slist => getvalues("info[uid]");
>
> "bla_$(user_crap1)" string => format("%S",
> "info[$(user_crap1)]");
>
>
> reports:
>
> "child function, only numbers instead if key names : data:
> $(with)" with => string_mustache("{{%-top-}}", user_crap1);
>
> "child funtion, mergedate produces empty output: $(with)" with =>
> string_mustache("{{%-top-}}", user_crap2);
>
> "child function, getvalues also not working : data: $(with)" with
> => string_mustache("{{%-top-}}", user_crap3);
>
> "Some mehtod from the docs, also nothing: $(user_crap1):
> $(bla_$(user_crap1))";
>
> }
>
>
> bundle agent __main__
> {
> methods:
> "parent_bundle";
> }
>
> data format:
>
> {
> "group": "pathetic",
> "name": "Michael Scott",
> "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
> "uid": "mscott"
> },
> {
> "group": "pathetic",
> "name": "John Krasinski",
> "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
> "uid": "jkras"
> },
> {
> "group": "tedious",
> "name": "Toby Flenderson",
> "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
> "uid": "tflen"
> },
> {
> "group": "buzzoff",
> "name": "Get OUT!",
> "ssh_key": "ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg",
> "uid": "fired"
> }
>
> how to i access uid, name,...from this structure?
>
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/cff5d29a-c83c-4d42-9974-806389699673n%40googlegroups.com.