Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created October 31, 2019 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickanderson/e2ae3ec55b70402c313c8f4ea78866e1 to your computer and use it in GitHub Desktop.
Save nickanderson/e2ae3ec55b70402c313c8f4ea78866e1 to your computer and use it in GitHub Desktop.

Help craig understand pre-eval

Created From: ~/Northern.Tech/CFEngine/masterfiles/promises.cf.in

How can I prevent a variable from being defined when the bundle is not explicitly actuated (part of bundlesequence or called via methods)?

bundle agent foo {
  vars:
    "test_thing" string => "I am here";
}
bundle agent main {
  classes:
    "something_exists"
      expression => fileexists( "/tmpx" ); 

  # I can change the above from /tmp to /tmpx and test_thing is always defined
  methods:
    something_exists::
      "foo";
  reports:
    something_exists::
      "something_exists is defined";
    !something_exists::
      "something_exists is NOT defined";
    any::
    "foo.test_thing=$(foo.test_thing)";
}
bundle agent foo {
  vars:
    "test_thing"
      string => "I am here",
      depends_on => { "delay_until_bundle_actuated" },
      comment => "Since this promise depends on a promsie that is only actuated
      during the full 3 pass convergence, it won't be defined unless the bundle
      is called. Furthermore, it won't be defined unitl the second pass of the
      bundle.";

  commands:
    "/bin/true" handle => "delay_until_bundle_actuated";
}

bundle agent main {
  classes:
    "something_exists"
      expression => fileexists( "/tmpx" ); 

  # I can change the above from /tmp to /tmpx and test_thing is always defined
  methods:
    something_exists::
      "foo";
  reports:
    something_exists::
      "something_exists is defined";
    !something_exists::
      "something_exists is NOT defined";
    any::
    "foo.test_thing=$(foo.test_thing)";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment