From 17dac6412eab6e8bc8318a5d4eb70ed68a23a06e Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Thu, 28 Aug 2025 12:23:11 -0500 Subject: [PATCH 1/2] Enhanced default bodies documentation and examples Clarified the explanation of default bodies, added CFEngine code examples for their definition and application, and included historical context. Ticket: CFE-4583 Changelog: None (cherry picked from commit 380cc455428dd9e7d9a0737d80494c4cc419ca17) --- reference/language-concepts/bodies.markdown | 67 ++++++++++++++++++--- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/reference/language-concepts/bodies.markdown b/reference/language-concepts/bodies.markdown index d992c1b06..35fa93dcb 100644 --- a/reference/language-concepts/bodies.markdown +++ b/reference/language-concepts/bodies.markdown @@ -171,21 +171,57 @@ Agents][Components] #### Default bodies -CFEngine 3.9 introduced a way to create default bodies. It allows defining, for given -promise and body types, a body that will be used each time no body is defined. -To use a body as default, name it `_` and put it -in the `bodydefault` namespace. For example, a default `action` body for `files` -promises will be named `files_action`, and in each `files` promise, if no -`action` attribute is set, the `files_action` action will be used. +Default bodies are automatically attached to promises not already using that +body in the default namespace. To use a body as default, name it +`_` and put it in the `bodydefault` namespace. + +```cf3 +body file control +{ + # Default bodies /must/ be defined in the /default/ namespace + namespace => "bodydefault"; +} + +body _ +{ + # Attributes set for body will be applied to all + # promises that do not already have a body of attached. +} +``` + +For example, a default `action` body for `files` promises will be named +`files_action`, and in each `files` promise, if no `action` attribute is set, +the `files_action` action will be used. **Note:** The default bodies **only** apply to promises in the `default` namespace. In the following example, we define a default `action` body for `files` -promises, that specifies an `action_policy => "warn"` to prevent actually modifying files -and to only warn about considered modifications. We define it once, -and don't have to explicitly put this body in all our `files` promises. +promises, that specifies an `action_policy => "warn"` to prevent actually +modifying files and to only warn about considered modifications. We define it +once, and don't have to explicitly put this body in all our `files` promises. +The example also illustrates how promises in a non-`default` namespace are +unaffected. ```cf3 +bundle agent example +{ + files: + + # Since the 'files_action' action body is defined in the 'bodydefault' namespce, + # and since this promise is in the 'default' namespace (no alternate namespace is + # declared previously) this promise will not actually modify the file content if + # it is not as promised. Instead it will warn that a change wants to be made. + + "/etc/motd" + content => "There are, in fact, rules. You have been notified."; + + # Since this promise has an action body attached, the default action body for + # files will not be applied and this file would be fixed. + + "/etc/issue.net" + content => "WARNING: You are being monitored. We are all being monitored. This is a cry for help.", + action => if_elapsed_day; +} body file control { namespace => "bodydefault"; @@ -198,6 +234,17 @@ body action files_action body file control { - namespace => "default"; + namespace => "not_affected"; +} + +bundle agent not_affected +{ + files: + "/etc/not-affected-by-bodydefault-files-action-body" + content => "Hello world!"; } ``` + +**History:** + +- Added in CFEngine 3.9.0 From 81cf40c040382b05b1e5f3019579b2112000414f Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Thu, 28 Aug 2025 13:30:38 -0500 Subject: [PATCH 2/2] Update content/reference/language-concepts/bodies.markdown Co-authored-by: Craig Comstock (cherry picked from commit 691ae210380306c87ccde3fa43554a7dccac54cb) --- reference/language-concepts/bodies.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/language-concepts/bodies.markdown b/reference/language-concepts/bodies.markdown index 35fa93dcb..12f7f724b 100644 --- a/reference/language-concepts/bodies.markdown +++ b/reference/language-concepts/bodies.markdown @@ -178,7 +178,7 @@ body in the default namespace. To use a body as default, name it ```cf3 body file control { - # Default bodies /must/ be defined in the /default/ namespace + # Default bodies /must/ be defined in the /bodydefault/ namespace namespace => "bodydefault"; }