Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created July 3, 2024 14:08
Show Gist options
  • Save nickanderson/5eecd6cd836943ac50f751fcdf537a77 to your computer and use it in GitHub Desktop.
Save nickanderson/5eecd6cd836943ac50f751fcdf537a77 to your computer and use it in GitHub Desktop.
Reproduce policy from chat
bundle agent __main__
{

    vars:
    "repo_data" data => '{"one": { "value": "something" }, "two": { "run_class": "linux" } }';
    "repo_names" slist => getindices(repo_data);
    reports:
          "$(this.bundle): yes or/not $(repo_names)"
              if => or(
                  canonify("$(repo_data[$(repo_names)][run_class])"),
                  not(isvariable("repo_data[$(repo_names)][run_class]"))
                  );
}
R: main: yes or/not two
@nickanderson
Copy link
Author

Debug doens't show the skip ...

     debug: DeRefCopyPromise():     copying constraint: 'if'
     debug: Starting iteration engine with 2 wheels   ---   ENTERING WARP SPEED
     debug: Evaluating function: canonify("$(repo_data[$(repo_names)][run_class])")
     debug: Evaluating function: isvariable("repo_data[$(repo_names)][run_class]")
     debug: Evaluating function: not(isvariable("repo_data[$(repo_names)][run_class]"))
     debug: Evaluating function: or(canonify("$(repo_data[$(repo_names)][run_class])"),not(isvariable("repo_data[$(repo_names)][run_class]")))
   verbose: P: .........................................................
   verbose: P: BEGIN promise 'promise_cfengine3_Fbnrek_8' of type "reports" (pass 1)
   verbose: P:    Promiser/affected object: 'main: yes or/not two'
   verbose: P:    Part of bundle: main
   verbose: P:    Base context class: any
   verbose: P:    "if" class condition: any
   verbose: P:    Stack path: /default/main/reports/'main: yes or/not two'[1]
  R: main: yes or/not two
   verbose: A: Promise was KEPT
   verbose: P: END reports promise (main: yes or/not two)
     debug: Iteration engine finished   ---   WARPING OUT
   verbose: V: .........................................................
   verbose: V: BEGIN variables (pass 2)

@nickanderson
Copy link
Author

With log-modules=all

     debug: Expanded scalar 'repo_data[$(repo_names)][run_class]' to 'repo_data[one][run_class]' using default namespace and current scope.
     debug: VariableTableGet(default:main.repo_data[one][run_class]): NOT FOUND
     debug: VariableTableGet(default:this.main___repo_data[one][run_class]): NOT FOUND

@basvandervlies
Copy link

I have added this statement to solve it:

            "repo_data[$(repo_names)][run_class]" string => "any",                                                                                                                   
                unless => isvariable("repo_data[$(repo_names)][run_class]"); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment