Skip to content

Commit fe76038

Browse files
authored
Merge pull request #3554 from nickanderson/body-file-control-evaluation-order/master
Added documentation for evaluation_order in file control body
2 parents 910ac6e + 3f4d785 commit fe76038

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

content/examples/tutorials/policy-writing/policy-style.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ significantly easier for a novice to understand the desired state.
8787
Historically, it was important to remember that Normal ordering still applied and
8888
that the promises would not be actuated in the order they are written. However,
8989
as of CFEngine 3.27.0, you can use `evaluation_order => "top_down";` in
90-
`body common control` or `body agent control` to make the execution order match
91-
the written order.
90+
`body common control`, `body agent control`, or `body file control` to make the
91+
execution order match the written order.
9292

9393
```cf3
9494
body common control

content/reference/components/_index.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ body common control
245245
}
246246
```
247247

248-
**See also:** [`evaluation_order` in `body common control`][cf-agent#evaluation_order], [Policy style guide on promise ordering][Policy style guide#Promise ordering]
248+
**See also:** [`evaluation_order` in `body agent control`][cf-agent#evaluation_order], [Policy style guide on promise ordering][Policy style guide#Promise ordering]
249249

250250
**History:**
251251

content/reference/components/file_control_promises.markdown

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,66 @@ outside of body and bundle definitions.
2626
Only [soft classes][Classes and decisions] from common bundles can
2727
be used in class decisions inside `file control bodies`.
2828

29+
### evaluation_order
30+
31+
**Description:** `evaluation_order` in body file control sets the evaluation order for the subsequent bundles in the file.
32+
33+
This setting allows you to change the order in which components execute policy within a given policy file.
34+
By default, CFEngine uses a `classic` evaluation order, where promises are executed in a predefined order based on their type (e.g., `vars` before `files`, `files` before `packages`, etc.).
35+
This is the historical behavior of CFEngine.
36+
37+
By setting `evaluation_order` to `top_down`, you can force components to evaluate promises in the order they are written in the policy file, from top to bottom.
38+
This can make policy evaluation more familiar and possibly easier to write and understand, especially for new users, as the execution flow follows the visual layout of the code.
39+
40+
This attribute can also be set in `body common control` to affect all components and or `body agent control` to affect all files.
41+
If set in multiple places, the value in `body agent control` takes precedence for `cf-agent`.
42+
43+
**Type:** `string`
44+
45+
**Allowed input range:** `(classic|top_down)`
46+
47+
**Default value:** `classic`
48+
49+
**Example:**
50+
51+
```cf3
52+
body file control
53+
{
54+
evaluation_order => "top_down";
55+
}
56+
57+
bundle agent reports_top_down
58+
{
59+
reports: "Hello world:";
60+
61+
commands: "/bin/echo hi";
62+
63+
reports: "bye:";
64+
}
65+
bundle agent __main__
66+
{
67+
methods: "reports_top_down";
68+
}
69+
70+
body agent control
71+
{
72+
evaluation_order => "top_down";
73+
}
74+
```
75+
76+
Executed would result in:
77+
78+
```output
79+
R: Hello world:
80+
notice: Q: ".../bin/echo hi": hi
81+
R: bye:
82+
```
83+
84+
**See also:** [`evaluation_order` in `body agent control`](/reference/components/cf-agent/#evaluation_order),
85+
[`evaluation_order` in `body common control`][Components#evaluation_order]
86+
87+
**History:** Introduced in CFEngine 3.27.0
88+
2989
### inputs
3090

3191
**Description:** The `inputs` slist contains additional filenames to parse for promises.

content/reference/language-concepts/policy-evaluation.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ as early as possible in your configuration. In order to make sure all global
3333
variables and classes are available early enough policy pre-evaluation step was
3434
introduced.
3535

36+
Note: Since CFEngine 3.27.0 it's possible to configure the evaluation order from
37+
the pre-defined normal order to the written order, top down.
38+
39+
**See also:** [`evaluation_order` in `body agent control`](/reference/components/cf-agent/#evaluation_order), [`evaluation_order` in `body common control`][Components#evaluation_order], [`evaluation_order` in `body file control`][file control#evaluation_order]
40+
3641
### Policy evaluation overview
3742

3843
CFEngine policy evaluation is done in several steps:

0 commit comments

Comments
 (0)