@@ -170,21 +170,57 @@ Agents][Components]
170
170
171
171
#### Default bodies
172
172
173
- CFEngine 3.9 introduced a way to create default bodies. It allows defining, for given
174
- promise and body types, a body that will be used each time no body is defined.
175
- To use a body as default, name it ` <promise_type>_<body_type> ` and put it
176
- in the ` bodydefault ` namespace. For example, a default ` action ` body for ` files `
177
- promises will be named ` files_action ` , and in each ` files ` promise, if no
178
- ` action ` attribute is set, the ` files_action ` action will be used.
173
+ Default bodies are automatically attached to promises not already using that
174
+ body in the default namespace. To use a body as default, name it
175
+ ` <promise_type>_<body_type> ` and put it in the ` bodydefault ` namespace.
176
+
177
+ ``` cf3
178
+ body file control
179
+ {
180
+ # Default bodies /must/ be defined in the /default/ namespace
181
+ namespace => "bodydefault";
182
+ }
183
+
184
+ body <body_type> <promise_type>_<body_type>
185
+ {
186
+ # Attributes set for body <body_type> will be applied to all <promise_type>
187
+ # promises that do not already have a body of <body_type> attached.
188
+ }
189
+ ```
190
+
191
+ For example, a default ` action ` body for ` files ` promises will be named
192
+ ` files_action ` , and in each ` files ` promise, if no ` action ` attribute is set,
193
+ the ` files_action ` action will be used.
179
194
180
195
** Note:** The default bodies ** only** apply to promises in the ` default ` namespace.
181
196
182
197
In the following example, we define a default ` action ` body for ` files `
183
- promises, that specifies an ` action_policy => "warn" ` to prevent actually modifying files
184
- and to only warn about considered modifications. We define it once,
185
- and don't have to explicitly put this body in all our ` files ` promises.
198
+ promises, that specifies an ` action_policy => "warn" ` to prevent actually
199
+ modifying files and to only warn about considered modifications. We define it
200
+ once, and don't have to explicitly put this body in all our ` files ` promises.
201
+ The example also illustrates how promises in a non-` default ` namespace are
202
+ unaffected.
186
203
187
204
``` cf3
205
+ bundle agent example
206
+ {
207
+ files:
208
+
209
+ # Since the 'files_action' action body is defined in the 'bodydefault' namespce,
210
+ # and since this promise is in the 'default' namespace (no alternate namespace is
211
+ # declared previously) this promise will not actually modify the file content if
212
+ # it is not as promised. Instead it will warn that a change wants to be made.
213
+
214
+ "/etc/motd"
215
+ content => "There are, in fact, rules. You have been notified.";
216
+
217
+ # Since this promise has an action body attached, the default action body for
218
+ # files will not be applied and this file would be fixed.
219
+
220
+ "/etc/issue.net"
221
+ content => "WARNING: You are being monitored. We are all being monitored. This is a cry for help.",
222
+ action => if_elapsed_day;
223
+ }
188
224
body file control
189
225
{
190
226
namespace => "bodydefault";
@@ -197,6 +233,17 @@ body action files_action
197
233
198
234
body file control
199
235
{
200
- namespace => "default";
236
+ namespace => "not_affected";
237
+ }
238
+
239
+ bundle agent not_affected
240
+ {
241
+ files:
242
+ "/etc/not-affected-by-bodydefault-files-action-body"
243
+ content => "Hello world!";
201
244
}
202
245
```
246
+
247
+ ** History:**
248
+
249
+ - Added in CFEngine 3.9.0
0 commit comments