Skip to content

Commit 4310054

Browse files
authored
Merge pull request #3484 from olehermanse/master
Fixed / skipped policy snippets
2 parents f17f46a + c4de82e commit 4310054

23 files changed

+142
-149
lines changed

cheatsheet.markdown

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ Linux
246246
```
247247

248248
You might also specify output syntax highlighting by adding language
249-
after the starting backticks and placing `[output]` in the first line.
250-
This line won't be shown in the resulted HTML.
249+
after the starting backticks and placing `{output}` at the end of the line.
251250

252251
```command
253252
curl --user admin:admin https://test.cfengine.com/api/user

content/examples/_index.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ from the example.
219219
3. Insert the example's bundle name in the `bundlesequence` section
220220
of the main policy file `/var/cfengine/masterfiles/promises.cf`:
221221

222-
```cf3
222+
```cf3 {skip TODO}
223223
bundlesequence => {
224224
...
225225
"hello_world",
@@ -230,7 +230,7 @@ from the example.
230230
4. Insert the policy file name in the [`inputs`][Components#inputs] section of the main policy file
231231
`/var/cfengine/masterfiles/promises.cf`:
232232

233-
```cf3
233+
```cf3 {skip TODO}
234234
inputs => {
235235
...
236236
"hello_world.cf",
@@ -241,7 +241,7 @@ from the example.
241241
5. You must also remove any inputs section from the example that
242242
includes the external library:
243243

244-
```cf3
244+
```cf3 {skip TODO}
245245
inputs => {
246246
"libraries/cfengine_stdlib.cf"
247247
};

content/examples/example-snippets/promise-patterns/example_aborting_execution.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Copy and paste `abortbundleclasses => { "invalid" };` into
4242
`/var/cfengine/masterfiles/controls/cf_agent.cf`. If you add it to
4343
the end of the file it should look something like this:
4444

45-
```cf3
45+
```cf3 {skip TODO}
4646
...
4747
# dryrun => "true";
4848

content/examples/tutorials/distribute-files-from-a-central-location.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ These variables provide path definitions for storing and deploying patches.
4646

4747
Add the following variable information to the `masterfiles/def.cf` file:
4848

49-
```cf3 {file="def.cf"}
49+
```cf3 {file="def.cf" skip TODO}
5050
"dir_patch_store"
5151
string => "/storage/patches",
5252
comment => "Define patch files source location",

content/examples/tutorials/integrating-with-sumo-logic.markdown

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ First, we define a couple of variables.
2929

3030
The two Sumo variables are used to access the service, while the `curl_args` is the actual curl command that will upload our timestamp file to Sumo Logic.
3131

32-
```cf3
32+
```cf3 {skip TODO}
3333
vars:
3434
"policy_update_file"
3535
string => "/tmp/CFEngine_policy_updated";
@@ -47,7 +47,7 @@ We also ensures that the content of this file will be the value of the `sys.last
4747

4848
Finally, below you will see a body defining how CFEngine is going to detect changes in policy files, this time using an md5 hash and only looking for change in the content (not permissions or ownership).
4949

50-
```cf3
50+
```cf3 {skip TODO}
5151
files:
5252
"$(policy_update_file)"
5353
create => "true",
@@ -71,7 +71,7 @@ The final section in the CFEngine policy is where the command that uploads the f
7171

7272
The command will only be issued whenever a class called `new_policy_update` is set, which we above defined to be set when there is a change detection. The handle argument is a useful way to document your intentions.
7373

74-
```cf3
74+
```cf3 {skip TODO}
7575
commands:
7676
new_policy_update::
7777
"/usr/bin/curl"
@@ -105,7 +105,7 @@ Normally, to ensure your policy file is put into action, you would need to follo
105105

106106
Under the body common control, add `sumo_logic_policy_update` to your bundle sequence.
107107

108-
```cf3
108+
```cf3 {skip TODO}
109109
body common control
110110
111111
{
@@ -118,7 +118,7 @@ body common control
118118

119119
Under body common control, add /sumologic_policy_update.cf/ to your inputs section.
120120

121-
```cf3
121+
```cf3 {skip TODO}
122122
inputs => {
123123
# File definition for global variables and classes
124124
"sumologic_policy_update.cf",

content/examples/tutorials/json-yaml-support-in-cfengine.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ through them and look up values.
109109

110110
Well, you can change
111111

112-
```cf3
112+
```cf3 {skip TODO}
113113
"bykey" data => parsejson('{ "dev": ["c", "b"], "prod": ["flea"], "qa": ["a"], "private": ["linux"] }');
114114
```
115115

116116
with
117117

118-
```cf3
118+
```cf3 {skip TODO}
119119
"bykey" data => data_readstringarray(...);
120120
```
121121

@@ -131,7 +131,7 @@ private linux
131131

132132
You can also use
133133

134-
```cf3
134+
```cf3 {skip TODO}
135135
"bykey" data => readjson(...);
136136
```
137137

content/examples/tutorials/manage-ntp.markdown

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ You can think of bundles as a collection of desired states. You can have as many
3434

3535
#### vars
3636

37-
```cf3
37+
```cf3 {skip TODO}
3838
vars:
3939
```
4040

4141
`vars` is a promise type that ensures the presence of variables that hold specific values. `vars:` starts a promise type block which ends when the next promise type block is declared.
4242

4343
##### ntp_package_name
4444

45-
```cf3
45+
```cf3 {skip TODO}
4646
"ntp_package_name" string => "ntp";
4747
```
4848

4949
A variable with the name `ntp_package_name` is declared and it is assigned a value, `ntp`. This string variable will be referenced in the other sections of the bundle.
5050

5151
#### packages
5252

53-
```cf3
53+
```cf3 {skip TODO}
5454
packages:
5555
"$(ntp_package_name)" -> { "StandardsDoc 3.2.1" }
5656
policy => "present",
@@ -62,7 +62,7 @@ packages:
6262

6363
##### $(ntp_package_name)
6464

65-
```
65+
```cf3 {skip TODO}
6666
"$(ntp_package_name)" -> { "StandardsDoc 3.2.1" }
6767
```
6868

@@ -72,23 +72,23 @@ This promiser has a number of additional attributes defined:
7272

7373
###### policy
7474

75-
```cf3
75+
```cf3 {skip TODO}
7676
policy => "present",
7777
```
7878

7979
The package_policy attribute describes what you want to do the package. In this case you want to ensure that it is present on the system. Other valid values of this attribute include delete, update, patch, reinstall, addupdate, and verify. Because of the self-healing capabilities of CFEngine, the agents will continuously check to make sure the package is installed. If it is not installed, CFEngine will try to install it according to its policy.
8080

8181
###### handle
8282

83-
```cf3
83+
```cf3 {skip TODO}
8484
handle => "ntp_packages_$(ntp_package_name)",
8585
```
8686

8787
The handle uniquely identifies a promise within a policy. A recommended naming scheme for the handle is `bundle_name_promise_type_class_restriction_promiser`. It is often used for documentation and compliance purposes. As shown in this example, you can easily substitute values of variables for the handle.
8888

8989
###### classes
9090

91-
```cf3
91+
```cf3 {skip TODO}
9292
classes => results("bundle", "ntp_package_");
9393
```
9494

@@ -134,16 +134,10 @@ Validate it.
134134
python -m json.tool < def.json
135135
```
136136

137-
```output
137+
```json {output}
138138
{
139-
"inputs": [
140-
"services/ntp.cf"
141-
],
142-
"vars": {
143-
"control_common_bundlesequence_end": [
144-
"ntp"
145-
]
146-
}
139+
"inputs": ["services/ntp.cf"],
140+
"vars": { "control_common_bundlesequence_end": ["ntp"] }
147141
}
148142
```
149143

@@ -213,7 +207,7 @@ Let's dissect this policy and review the differences in the policy.
213207

214208
#### vars
215209

216-
```cf3
210+
```cf3 {skip TODO}
217211
redhat::
218212
"ntp_service_name" string => "ntpd";
219213
debian::
@@ -224,7 +218,7 @@ The first thing that you will notice is that the variable declarations section h
224218

225219
#### reports
226220

227-
```cf3
221+
```cf3 {skip TODO}
228222
reports:
229223
ntp_service_repaired.inform_mode::
230224
"NTP service repaired";
@@ -238,7 +232,7 @@ ntp_service_repaired.inform_mode::
238232

239233
This line restricts the context for the promises that follow to hosts that have `ntp_service_repaired` and `inform_mode` defined. Note: `inform_mode` is defined when information level logging is requested, e.g. the `-I`, `--inform`, or `--log-level inform` options are given to `cf-agent` defined.
240234

241-
```cf3
235+
```cf3 {skip TODO}
242236
"NTP service repaired";
243237
```
244238

@@ -360,7 +354,7 @@ Let's review the different sections of the code, starting with the variable decl
360354

361355
#### vars
362356

363-
```cf3
357+
```cf3 {skip TODO}
364358
vars:
365359
linux::
366360
"ntp_package_name" string => "ntp";
@@ -390,7 +384,7 @@ A few new variables are defined. The variables `ntp_package_name`, `config_file`
390384

391385
Now let's walk through the files promise in detail.
392386

393-
```cf3
387+
```cf3 {skip TODO}
394388
files:
395389
"$(config_file)"
396390
create => "true",
@@ -406,55 +400,55 @@ The promiser here is referenced by the `config_file` variable. In this case, it
406400

407401
##### create
408402

409-
```cf3
403+
```cf3 {skip TODO}
410404
create => "true",
411405
```
412406

413407
Valid values for this attribute are `true` or `false` to instruct the agent whether or not to create the file. In other words, the file must exist. If it does not exist, it will be created.
414408

415409
##### perms
416410

417-
```cf3
411+
```cf3 {skip TODO}
418412
perms => mog( "644", "root", "root" ),
419413
```
420414

421415
This attribute sets the permissions and ownership of the file. [`mog()`][stdlib-mog] is a `perms` body in the CFEngine standard library that sets the `mode`, `owner`, and `group` of the file. In this example, the permissions for the NTP configuration file are set to `644` with _owner_ and _group_ both assigned to `root`.
422416

423417
##### handle
424418

425-
```cf3
419+
```cf3 {skip TODO}
426420
handle => "ntp_files_conf",
427421
```
428422

429423
A handle uniquely identifies a promise within a policy set. The [policy style guide][Policy style guide#promise handles] recommends a naming scheme for the handles e.g. `bundle_name_promise_type_class_restriction_promiser`. Handles are optional, but can be very useful when reviewing logs and can also be used to influence promise ordering with `depends_on`.
430424

431425
##### classes
432426

433-
```cf3
427+
```cf3 {skip TODO}
434428
classes => results( "bundle", "ntp_config" );
435429
```
436430

437431
The classes attribute here uses the [`results()`][lib/common.cf#results] classes body from the standard library. The `results()` body defines classes for every outcome a promise has. Every time this promise is executed classes will be defined bundle scoped classes prefixed with `ntp_config`. If the promise changes the file content or permissions the class `ntp_config_repaired` will be set.
438432

439433
##### template_method
440434

441-
```cf3
435+
```cf3 {skip TODO}
442436
template_method => "inline_mustache",
443437
```
444438

445439
CFEngine supports multiple templating engines, the [template_method][files#template_method] attribute specifies how the promised file content will be resolved. The value `inline_mustache` indicates that we will use the mustache templating engine and specify the template in-line, instead of in an external file.
446440

447441
##### edit_template_string
448442

449-
```cf3
443+
```cf3 {skip TODO}
450444
edit_template_string => "$(config_template_string)",
451445
```
452446

453447
The `edit_template_string` attribute is set to `$(config_template_string)` which holds the mustache template used to render the file content.
454448

455449
##### template_data
456450

457-
```cf3
451+
```cf3 {skip TODO}
458452
template_data => mergedata( '{ "driftfile": "$(driftfile)", "servers": servers }' ),
459453
```
460454

content/examples/tutorials/render-files-with-mustache-templates.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bundle agent myapp_confs
7878
}
7979
');
8080
}
81-
body agent __main__
81+
bundle agent __main__
8282
{
8383
methods:
8484
"myapp_confs";

content/examples/tutorials/reporting/command-line-reports.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ reports:
176176

177177
A bonus to this is that you can get CFEngine to report system anomalies:
178178

179-
```cf3
179+
```cf3 {skip TODO}
180180
reports:
181181
182182
rootprocs_high_dev2::

content/examples/tutorials/tags.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ way to categorize various data accessible to the agent.
114114
Dynamic bundlesequences are extremely easy. First you find all the bundles whos
115115
name matches a regular expression and N tags.
116116

117-
```cf3
117+
```cf3 {skip TODO}
118118
vars:
119119
"bundles" slist => bundlesmatching("regex", "tag1", "tag2", ...);
120120
```
121121

122122
Then every bundle matching the regular expression `regex` and **all**
123123
the tags will be found and run.
124124

125-
```cf3
125+
```cf3 {skip TODO}
126126
methods:
127127
"run $(bundles)" usebundle => $(bundles);
128128
```

0 commit comments

Comments
 (0)