Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3403

Adjacent body file control with inputs only parses first set of inputs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Low
    • Resolution: Unresolved
    • Affects Version/s: 3.16.0
    • Fix Version/s: None
    • Component/s: cf-agent, Evaluation, Parsing
    • Labels:
      None
    • Story Points:
      5

      Description

      For example, I have 3 policy files: example_library_main.cf, example_librarymain1.cf, and example_librarymain2.cf. Each can be run directly leveraging a bundle agent __main that is present in each file. example_librarymain_.cf includes the other two files via body file control inputs and runs bundles from each of the files.

      example_library_main_.cf
      #!/var/cfengine/bin/cf-agent -f-
      body file control
      {
            inputs => { '$(sys.libdir)/stdlib.cf' };
      }
      
      body file control
      {
        inputs => {
                    "example_library__main__1.cf",
                    "example_library__main__2.cf",
                  };
      }
      bundle agent example_library__main__
      {
        reports: "Hello from $(this.bundle)";
      }
      bundle agent __main__
      {
        vars: "b" slist => bundlesmatching( "example_.*" );
        methods:
            "example_library__main__";
            "example_library__main__1";
            "example_library__main__2";
        reports: "$(b)";
      }
      
      example_library_main_1.cf
      #!/var/cfengine/bin/cf-agent -f-
      body file control
      {
            inputs => { '$(sys.libdir)/stdlib.cf' };
      }
      
      bundle agent example_library__main__1
      {
        reports: "Hello from $(this.bundle)";
      }
      bundle agent __main__
      {
        methods:
            "example_library__main__1";
      }
      
      
      example_library_main_2.cf
      #!/var/cfengine/bin/cf-agent -f-
      body file control
      {
            inputs => { '$(sys.libdir)/stdlib.cf' };
      }
      
      bundle agent example_library__main__2
      {
        reports: "Hello from $(this.bundle)";
      }
      bundle agent __main__
      {
        methods:
            "example_library__main__2";
      }
      
      

      When executed, I get errors about missing bundles.

      Executing examples/library_main/example_librarymain_.cf
      cf-agent -KIf ./example_library__main__.cf
      
      R: Hello from example_library__main__
         error: A method attempted to use a bundle 'example_library__main__1' that was apparently not defined
         error: A method attempted to use a bundle 'example_library__main__2' that was apparently not defined

      I don't think this is something most people will run into. My files only contain two body file control sections adjacently because they were tangled out from org-mode using ob-cfengine3 and the first that includes the stdlib was automatically inserted, and that's something I can fix, but it was unexpected, and took me a bit to identify the issue.

      To be clear, stripping the first body file control resolves the issue.

      example_library_main_.cf with workaround
      #!/var/cfengine/bin/cf-agent -f-
      body file control
      {
        inputs => {
                    "example_library__main__1.cf",
                    "example_library__main__2.cf",
                  };
      }
      bundle agent example_library__main__
      {
        reports: "Hello from $(this.bundle)";
      }
      bundle agent __main__
      {
        vars: "b" slist => bundlesmatching( "example_.*" );
        methods:
            "example_library__main__";
            "example_library__main__1";
            "example_library__main__2";
        reports: "$(b)";
      }
      
      > $ cf-agent -KIf ./example_library__main__.cf
      R: Hello from example_library__main__
      R: Hello from example_library__main__1
      R: Hello from example_library__main__2
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              a10042 Nick Anderson
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Summary Panel