Re: Re: classfiltercsv: filtering only works on bundle level
"'Nick Anderson' via help-cfengine" <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
Xander Cage <[email protected]> writes: i forgot to mention that the above shows hat the "filter classes" in the classesfiltercsv function not "filtering" when used in various child bundles if the definition of the datacontainer or the call to the classfiltercsv function is not present in the bundle. Reading the policy ..., you are using `classfiltercsv()' inside of `bundle agent parent_bundle'. Running with your data set I get no data container defined, for example: ,---- | # cf-agent --no-lock --log-level info --show-evaluated-vars=parent_bundle --file /tmp/example.cf | R: check_user reached: $(user) | R: create_users reached: $(user) | R: parent bundle: $(user) | Variable name Variable value Meta tags Comment | default:parent_bundle.data_file /tmp/my.csv source=promise | default:parent_bundle.keys source=promise | default:parent_bundle.keys_unsorted source=promise | default:parent_bundle.my_data [] source=promise `---- This is because none of the class expressions in your first (zeroth) column evaluate to true on my system in that bundle. So, I added a row that would (`any,nickanderson,Nick Anderson,neither-us-nor-them,ssh-bs') and I modified the policy to point to the path I am using for the CSV (`/tmp/my.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,wimm,,dbaldap,ssh-someSupERsecretKey287483438dsdjhdsdsdjahhsgdsg | any,nickanderson,Nick Anderson,neither-us-nor-them,ssh-bs `---- Listing 1: CSV Data (/tmp/my.csv) ,---- | bundle agent parent_bundle | { | | vars: | | "data_file" string => "/tmp/my.csv"; | "my_data" data => classfiltercsv( $(data_file), "true", 0); | | "keys_unsorted" slist => getindices(my_data); | | "keys" slist => sort(keys_unsorted, "lex"); | "user" string => "$(my_data[$(keys)][uid])"; | | | | methods: | | "call_check_user" usebundle => check_user( @(my_data) ), | handle => "remove_it"; | | "call_create_user" usebundle => create_users_new( @(my_data) ), | depends_on => { "remove_it" }; | | reports: | | "parent bundle: $(user)"; | | } | | | bundle agent check_user (info) { | | vars: | | "keys_unsorted" slist => getindices(info); | "keys" slist => sort(keys_unsorted, "lex"); | "user" string => "$(info[$(keys)][uid])"; | | classes: | | "zombie"; | | | reports: | | "check_user reached: $(user)"; | | | } | | | bundle agent create_users_new(info) { | | | vars: | "keys_unsorted" slist => getindices(info); | | "keys" slist => sort(keys_unsorted, "lex"); | | "user" string => "$(info[$(keys)][uid])"; | "group" string => "$(info[$(keys)][group])"; | "ssh_key" string => "$(info[$(keys)][ssh_key])"; | "name" string => "$(info[$(keys)][name])"; | | classes: | | "weirdos"; | "twats"; | | reports: | | "create_users reached: $(user)"; | | } | | bundle agent __main__ | { | methods: | "parent_bundle"; | } `---- Listing 2: Example Policy With that change, the rows with class expressions that evaluate to true become part of the data container that result from parsing. ,---- | # cf-agent --no-lock --log-level info --show-evaluated-vars=parent_bundle --file /tmp/example.cf | R: check_user reached: nickanderson | R: create_users reached: nickanderson | R: parent bundle: nickanderson | Variable name Variable value Meta tags Comment | default:parent_bundle.data_file /tmp/my.csv source=promise | default:parent_bundle.keys {"0"} source=promise | default:parent_bundle.keys_unsorted {"0"} source=promise | default:parent_bundle.my_data [{"group":"neither-us-nor-them","name":"Nick Anderson","ssh_key":"ssh-bs","uid":"nickanderson"}] source=promise | default:parent_bundle.user nickanderson source=promise `---- Reading the policy further ...., some bundles (`bundle agent check_user', and `bundle agent create_user_new') are promised as methods. Inside these bundles there are some bundle scope classes defined and some variables are created by pulling the data off of the previously defined data container that is passed in to the bundle as an argument. whats the deal if i have to define all filtering classes in the parent bundle? seems useless to me. this function is at least somewhat inconvenient , or i am doing something completely wrong. any insights? Yes, sorry to say, I think you have a completely different expectation of what the behavior should be than what it provides. To me, it looks like you expect `classfiltercsv()' to filter your data set when you access the data set. That might be a nifty function in it's own right, but that is not how `classfiltercsv()' behaves. `classfiltercsv()' filters the data as it is read in based on the context at that point in time. So, if you want one data set of the rows that match /weirdos/ and /twats/ and another data set consisting of the rows that match /zombie/ as I believe your example policy illustrates you would need to make 2 calls to `classfiltercsv()'. -- 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/87cznesiqn.fsf%40northern.tech. -- Nick Anderson | Doer of Things | (+1) 785-550-1767 | https://northern.tech -- 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/87cznesiqn.fsf%40northern.tech.