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]> |
Hi,
Hopefully this attaches itself to the correct thread, no email in my
inbox to respond to for this one. `¯\_(ツ)_/¯'
Can you provide a completely stand-alone policy so that we can easily
run and re-produce the problem you have?
Proceeding only with my internal parser :)....
Regarding `"only works if the data and filter classes are in the same
bundle"', I suspect that you are just seeing class scope at work. In the
documentation, [Classes and Decisions in Language Concepts of the
Reference manual] has a section on [Class scope] which talks about this
a bit. It looks like you are using classes that are defined with a
/bundle/ scope (only visible within that bundle) and when you call your
child_bundle you did not have it inherit the classes, so inside of
child_bundle, any /bundle/ scoped classes that were defined in
parent_bundle won't be visible.
,----
| bundle agent __main__
| {
| methods:
| "parent";
|
| }
| bundle agent parent
| {
| classes:
| "my_bundle_scoped_class_defined_in_parent";
|
| methods:
| "Write our child into our will"
| usebundle => child,
| inherit => "true";
|
| "Step children get the shaft by default"
| usebundle => step_child;
|
| }
| bundle agent child
| {
| reports:
| "$(this.bundle): I can see my_bundle_scoped_class_defined_in_parent since my parent wrote me into the will."
| if => "my_bundle_scoped_class_defined_in_parent";
| "$(this.bundle): I wasn't written into the will, at least I am not red-headed."
| unless => "my_bundle_scoped_class_defined_in_parent";
| }
| bundle agent step_child
| {
| reports:
| "$(this.bundle): I can see my_bundle_scoped_class_defined_in_parent since my parent wrote me into the will."
| if => "my_bundle_scoped_class_defined_in_parent";
| "$(this.bundle): I wasn't written into the will, at least I am not red-headed."
| unless => "my_bundle_scoped_class_defined_in_parent";
| }
`----
,----
| R: child: I can see my_bundle_scoped_class_defined_in_parent since my parent wrote me into the will.
| R: step_child: I wasn't written into the will, at least I am not red-headed.
`----
Regarding `"i want to use the data container as a somewhat "global"
variable without repeating it"' , I don't think that you have to repeat
the data container, you can pass it whole like you do, or pass it's
name. Either way, you don't get a variable registered in the state (see
`--show-evaluated-vars').
,----
| bundle agent __main__
| {
| vars:
| "my_data" data => '{ "data": "here" }';
|
| methods:
| "Pass data container"
| usebundle => example_1( @(my_data) );
|
| "Pass NAME of data container"
| usebundle => example_2( "$(this.namespace):$(this.bundle).my_data" );
| }
|
| bundle agent example_1(my_data)
| {
| vars: "my_data_$(this.bundle)" data => '{ "bundle": "$(this.bundle)" }';
| reports: "$(this.bundle):$(with)" with => storejson( @(my_data) );
| }
| bundle agent example_2(my_data)
| {
| vars: "my_data_$(this.bundle)" data => '{ "bundle": "$(this.bundle)" }';
| reports: "$(this.bundle):$(with)" with => storejson( $(my_data) );
| }
`----
Listing 1: Example Policy
,----
| # cf-agent --no-lock --log-level info --show-evaluated-vars=my_data --file /tmp/example.cf
| R: example_1:{
| "data": "here"
| }
| R: example_2:{
| "data": "here"
| }
| Variable name Variable value Meta tags Comment
| default:example_1.my_data_example_1 {"bundle":"example_1"} source=promise
| default:example_2.my_data_example_2 {"bundle":"example_2"} source=promise
| default:main.my_data {"data":"here"} source=promise
`----
Hope this helps ...
[Classes and Decisions in Language Concepts of the Reference manual]
<https://docs.cfengine.com/docs/3.18/reference-language-concepts-classes.html>
[Class scope]
<https://docs.cfengine.com/docs/3.18/reference-language-concepts-classes.html#class-scope>
--
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/8735p3bcxj.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/8735p3bcxj.fsf%40northern.tech.