Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions content/reference/promise-types/vars.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,15 @@ two_example_com::

(Promises within the same bundle are evaluated top to bottom, so vars promises further down in a bundle can overwrite previous values of a variable. See [policy evaluation][Policy evaluation] for more information).

## Defining variables in foreign bundles
## Variable injection - Defining variables in foreign bundles

As a general rule, variables can only be defined or re-defined from within the
bundle where they were defined. There are a few notable exceptions to this
general rule which are described below.
As a general rule, variables cannot be defined or re-defined (overwritten) from outside their bundle.
There are 4 exceptions to this rule:

1. `meta` promises define variables in a different meta-suffixed bundle (this bundle is special / "virtual" and does not exist in the policy file).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno that you want to increase the complexity here, I don't know that it adds much but IIRC these _meta suffixed bundles are not precluded from being defined in policy

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


#+begin_src cfengine3
  bundle agent main
  {
          methods:
         "one";
         "two";
   }
  bundle agent one
  {
        reports: "$(one_meta.tags)";
  }
  bundle agent one_meta
  {
        vars:
          "tags" slist => { "crazy", "stuff" };
  }
  bundle agent two
  {
        meta:
        "tags" slist => { "know", "what", "i'm", "sayin" };

        reports: "$(two_meta.tags)";
  }

#+end_src

#+RESULTS:
: R: crazy
: R: stuff
: R: know
: R: what
: R: i'm
: R: sayin

2. Defining variables into undefined ("virtual") bundles.
3. `commands` modules which communicate using the module protocol can define variables in any bundle.
4. Augments (`def.json`) / Host specific data (`host_specific.json`) can define variables in any bundle.

### Meta type promises

Expand Down
Loading