Skip to content

Commit 195fcab

Browse files
tuxmeamiharp
authored andcommitted
Work on OpenFact documentation
- Change wording - Review examples and text - Add new information Signed-off-by: Martin Alfke <ma@betadots.de>
1 parent 0e91011 commit 195fcab

4 files changed

Lines changed: 72 additions & 172 deletions

File tree

docs/_openfact_5x/_facter_toc.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/_openfact_5x/custom_facts.md

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ layout: default
33
title: "Custom facts walkthrough"
44
---
55

6-
[Facter 3.0.2 release notes]: ../3.0/release_notes.html#facter--p-restored
7-
[Plugins in Modules]: /docs/puppet/latest/plugins_in_modules.html
8-
[Adding plug-ins to a module]: /docs/puppet/latest/plugins_in_modules.html#adding-plug-ins-to-a-module
6+
[Plugins in Modules]: /openvox/latest/plugins_in_modules.html
7+
[Adding plug-ins to a module]: /openvox/latest/plugins_in_modules.html
8+
[Facts overview]: ./fact_overview.html
99

10-
You can add custom facts by writing snippets of Ruby code on the Puppet master. Puppet then uses [Plugins in Modules][] to distribute the facts to the client.
10+
You can add custom facts by adding snippets of Ruby code to the OpenVox server. OpenVox then uses [Plugins in Modules][] to distribute the facts to all agents.
1111

1212
For information on how to add custom facts to modules, see [Adding plug-ins to a module][].
1313

1414
## Adding custom facts to OpenFact
1515

1616
Sometimes you need to be able to write conditional expressions based on site-specific data that just isn't available via OpenFact, or perhaps you'd like to include it in a template.
1717

18-
Because you can't include arbitrary Ruby code in your manifests, the best solution is to add a new fact to OpenFact. These additional facts can then be distributed to Puppet clients and are available for use in manifests and templates, just like any other fact is.
18+
Because you can't include arbitrary Ruby code in your manifests, the best solution is to add a new fact to OpenFact. These additional facts can then be distributed to OpenVox agent and are available for use in manifests and templates, just like any other fact is.
1919

20-
> **Note:** Facter 3.0 removed the Ruby implementations of some features and replaced them with a [custom facts API](https://github.com/puppetlabs/facter/blob/master/Extensibility.md#custom-facts-compatibility). Any custom fact that requires one of the Ruby files previously stored in `lib/facter/util` fails with an error. For more information, see the [Facter 3.0 release notes](../3.0/release_notes.html).
20+
> **Note:** OpenFact provides a [custom facts API](https://github.com/openvoxproject/openfact/blob/master/Extensibility.md#custom-facts-compatibility).
2121
2222
## Loading custom facts
2323

@@ -51,10 +51,11 @@ OpenFact can take multiple `--custom-dir` options on the command line that speci
5151
to search for custom facts. OpenFact attempts to load all Ruby files in the specified directories.
5252
This allows you to do something like this:
5353

54-
$ ls my_facts
55-
system_load.rb
56-
$ ls my_other_facts
57-
users.rb
54+
#~/my_facts
55+
└── system_load.rb
56+
#~/my_other_facts
57+
└── users.rb
58+
5859
$ facter --custom-dir=./my_facts --custom-dir=./my_other_facts system_load users
5960
system_load => 0.25
6061
users => thomas,pat
@@ -65,23 +66,17 @@ OpenFact also checks the environment variable `FACTERLIB` for a delimited (semic
6566
other platforms) set of directories, and tries to load all Ruby files in those directories.
6667
This allows you to do something like this:
6768

68-
$ ls my_facts
69-
system_load.rb
70-
$ ls my_other_facts
71-
users.rb
69+
#~/my_facts
70+
└── system_load.rb
71+
#~/my_other_facts
72+
└── users.rb
73+
7274
$ export FACTERLIB="./my_facts:./my_other_facts"
7375
$ facter system_load users
7476
system_load => 0.25
7577
users => thomas,pat
7678

77-
> ### Note: Changes in built-in pluginsync support in Facter 3
78-
>
79-
> Facter 2.4 **deprecated** Facter's support for loading facts via Puppet's pluginsync
80-
> (the `-p` option), and Facter 3.0.0 **removed** the `-p` option. However, we reversed
81-
> this decision in Facter 3.0.2 and re-enabled the `-p` option. For details about current
82-
> and future support for this option, see the [Facter 3.0.2 release notes][].
83-
84-
## Two parts of every fact
79+
## Two parts of every custom fact
8580

8681
Most facts have at least two elements:
8782

@@ -90,16 +85,20 @@ Most facts have at least two elements:
9085

9186
Facts *can* get a lot more complicated than that, but those two together are the most common implementation of a custom fact.
9287

93-
## Executing shell commands in facts
88+
## Executing shell commands in custom facts
9489

95-
Puppet gets information about a system from OpenFact, and the most common way for OpenFact to
90+
OpenVox gets information about a system from OpenFact, and the most simple way for OpenFact to
9691
get that information is by executing shell commands. You can then parse and manipulate the
97-
output from those commands using standard Ruby code. The OpenFact API gives you a few ways to
92+
output from those commands using standard Ruby code.
93+
94+
> **Note:** However, it is important to also ceck if any of the OpenVox agent bundled Ruby Libraries can be used.
95+
96+
The OpenFact API gives you a few ways to
9897
execute shell commands:
9998

100-
- To run a command and use the output verbatim, as your fact's value, you can pass the command into `setcode` directly. For example: `setcode 'uname --hardware-platform'`
101-
- If your fact is more complicated than that, you can call `Facter::Core::Execution.execute('uname --hardware-platform')` from within the `setcode do`...`end` block. Whatever the `setcode` statement returns is used as the fact's value.
102-
- Your shell command is also a Ruby string, so you need to escape special characters if you want to pass them through.
99+
- To run a command and use the output verbatim, as your fact's value, you can pass the command into `setcode` directly. For example: `setcode 'uname --hardware-platform'`
100+
- If your fact is more complicated than that, you can call `Facter::Core::Execution.execute('uname --hardware-platform')` from within the `setcode do`...`end` block. Whatever the `setcode` statement returns is used as the fact's value.
101+
- Your shell command is also a Ruby string, so you need to escape special characters if you want to pass them through.
103102

104103
> **Note:** Not everything that works in the terminal works in a fact. You can use the pipe (`|`) and similar operators as you normally would, but Bash-specific syntax like `if` statements do not work. The best way to handle this limitation is to write your conditional logic in Ruby.
105104
@@ -109,10 +108,10 @@ To get the output of `uname --hardware-platform` to single out a specific type o
109108

110109
1. Start by giving the fact a name, in this case, `hardware_platform`.
111110

112-
2. Create your new fact in a file, `hardware_platform.rb` on the Puppet master server:
111+
2. Create your new fact in a file, `hardware_platform.rb` on an OpenVox agent system:
113112

114113
``` ruby
115-
# hardware_platform.rb
114+
#~/my_facts/hardware_platform.rb
116115

117116
Facter.add('hardware_platform') do
118117
setcode do
@@ -121,19 +120,19 @@ To get the output of `uname --hardware-platform` to single out a specific type o
121120
end
122121
```
123122

124-
3. Use the instructions in the [Plugins in Modules][] page to copy the new fact to a module and distribute it. During your next Puppet run, the value of the new fact is available to use in your manifests and templates.
123+
3. Use the instructions in the [Plugins in Modules][] page to copy the new fact to a module and distribute it. During your next OpenVox run, the value of the new fact is available to use in your manifests and templates.
125124

126-
## Using other facts
125+
## Accessing other facts
127126

128-
You can write a fact that uses other facts by accessing `Facter.value(:somefact)`.
127+
You can write a custom fact that uses other facts by accessing `Facter.value(:somefact)`.
129128
If the fact fails to resolve or is not present, OpenFact returns `nil`.
130129

131130
For example:
132131

133132
``` ruby
134133
Facter.add(:osfamily) do
135134
setcode do
136-
distid = Facter.value(:lsbdistid)
135+
distid = Facter.value(:os)['family']
137136
case distid
138137
when /RedHatEnterprise|CentOS|Fedora/
139138
'redhat'
@@ -146,11 +145,11 @@ Facter.add(:osfamily) do
146145
end
147146
```
148147

149-
## Configuring facts
148+
## Configuring custom facts
150149

151150
Facts have a few properties that you can use to customize how they are evaluated.
152151

153-
### Confining facts
152+
### Confining custom facts
154153

155154
One of the more commonly used properties is the `confine` statement, which
156155
restricts the fact to only run on systems that matches another given fact.
@@ -174,7 +173,9 @@ available on the given system. Since this is only available on Linux systems,
174173
we use the `confine` statement to ensure that this fact isn't needlessly run on
175174
systems that don't support this type of enumeration.
176175

177-
### Fact precedence
176+
> **Note:** More information on other ways to confine. e.g. files present can be found a the [Facts overview]
177+
178+
### Custom facts precedence
178179

179180
A single fact can have multiple **resolutions**, each of which is a different way
180181
of ascertaining what the value of the fact should be. It's very common to have
@@ -221,7 +222,9 @@ Facter.add(:role) do
221222
end
222223
```
223224

224-
### Execution timeouts
225+
> **Hint:** A weight above 1000 overwrites external facts
226+
227+
### Custom facts execution timeouts
225228

226229
Although this version of OpenFact does not support overall timeouts on resolutions, you can pass a timeout
227230
to `Facter::Core::Execution#execute`:
@@ -239,11 +242,11 @@ Facter.add(:sleep) do
239242
end
240243
```
241244

242-
## Structured facts
245+
## Structured custom facts
243246

244247
Structured facts take the form of either a hash or an array. To create a structured fact, return a hash or an array from the `setcode` statement.
245248

246-
You can see some relevant examples in the [writing structured facts](./fact_overview.html#writing-structured-facts) section of the [Fact Overview](./fact_overview.html).
249+
You can see some relevant examples in the [writing structured facts](./fact_overview.html#writing-structured-facts) section of the [Facts overview].
247250

248251
## Aggregate resolutions
249252

@@ -287,21 +290,21 @@ end
287290

288291
If the `chunk` blocks all return arrays or hashes, you can omit the `aggregate` block. If you do, OpenFact automatically merges all of your data into one array or hash and uses that as the fact's value.
289292

290-
For more examples of aggregate resolutions, see the [aggregate resolutions](./fact_overview.html#writing-facts-with-aggregate-resolutions) section of the [Fact Overview](./fact_overview.html) page.
293+
For more examples of aggregate resolutions, see the [aggregate resolutions](./fact_overview.html#writing-facts-with-aggregate-resolutions) section of the [Fact overview] page.
291294

292295
## Viewing fact values
293296

294-
[puppetdb]: /puppetdb/latest
297+
[OpenVox-DB]: /openvoxdb/latest
295298

296-
If your Puppet masters are configured to use [PuppetDB][puppetdb], you can view and search all of the facts for any node, including custom facts. See [the PuppetDB docs][puppetdb] for more info.
299+
If your Puppet masters are configured to use [OpenVox-DB][OpenVox-DB], you can view and search all of the facts for any node, including custom facts. See [the OpenVox-DB docs][openvoxdb] for more info.
297300

298301
## External facts
299302

300303
### What are external facts?
301304

302305
External facts provide a way to use arbitrary executables or scripts as facts, or set facts statically with structured data. If you've ever wanted to write a custom fact in Perl, C, or a one-line text file, this is how.
303306

304-
### Executable facts --- Unix
307+
### Executable external facts --- Unix
305308

306309
Executable facts on Unix work by dropping an executable file into the standard
307310
external fact path. A shebang (`#!`) is always required for executable facts on Unix. If the shebang is missing, the execution of the fact fails.
@@ -329,7 +332,7 @@ STDOUT in the format:
329332

330333
Using this format, a single script can return multiple facts.
331334

332-
### Executable facts --- Windows
335+
### Executable external facts --- Windows
333336

334337
Executable facts on Windows work by dropping an executable file into the external fact path. Unlike with Unix, the external facts interface expects Windows scripts to end with a known extension. Line endings can be either `LF` or `CRLF`. The following extensions are currently supported:
335338

@@ -345,11 +348,11 @@ As with Unix facts, each script must return key/value pairs on STDOUT in the for
345348

346349
Using this format, a single script can return multiple facts in one return.
347350

348-
#### Executable fact locations
351+
#### Executable eternal fact locations
349352

350-
The best way to distribute external executable facts is with pluginsync, which added support for them in [Puppet 3.4] (/puppet/3/reference/release_notes.html#preparations-for-syncing-external-facts)/[Facter 2.0.1](../2.0/release_notes.html#pluginsync-for-external-facts). To add external executable facts to your Puppet modules, just place them in <MODULEPATH>/<MODULE>/facts.d/.
353+
The best way to distribute external executable facts is with pluginsync, To add external executable facts to your OpenVox modules, just place them in <MODULEPATH>/<MODULE>/facts.d/.
351354

352-
If you're not using pluginsync, then external facts must go in a standard directory. The location of this directory varies depending on your operating system, whether your deployment uses Puppet Enterprise or open source releases, and whether you are running as root/Administrator. When calling facter from the command line, you can specify the external facts directory with the `--external-dir` option.
355+
If you're not using pluginsync, then external facts must go in a standard directory. The location of this directory varies depending on your operating system and whether you are running as root/Administrator. When calling OpenFact from the command line, you can specify the external facts directory with the `--external-dir` option.
353356

354357
> **Note:** These directories don't necessarily exist by default; you may need to create them. If you create the directory, make sure to restrict access so that only Administrators can write to the directory.
355358
@@ -371,9 +374,9 @@ When running as a non-root / non-Administrator user:
371374

372375
<HOME DIRECTORY>/.facter/facts.d/
373376

374-
> **Note:** You can only use custom facts as a non-root user if you have first [configured non-root user access]({{pe}}/deploy_nonroot-agent.html) and previously run Puppet agent as that same user.
377+
> **Note:** You can only use custom facts as a non-root user if you have previously run OpenVox agent as that same user.
375378
376-
#### Batch scripts
379+
#### Windows batch scripts
377380

378381
The file encoding for `.bat/.cmd` files must be `ANSI` or `UTF8 without BOM` (Byte Order Mark), otherwise you may get strange output.
379382

@@ -398,7 +401,7 @@ Here is a sample PowerShell script which outputs facts using the required format
398401

399402
You should be able to save and execute this PowerShell script on the command line.
400403

401-
### Structured data facts
404+
### Structured data based external facts
402405

403406
OpenFact can parse structured data files stored in the external facts directory and set facts based on their contents.
404407

@@ -433,7 +436,7 @@ key3=value3
433436

434437
As with executable facts, structured data files can set multiple facts at once.
435438

436-
``` javascript
439+
``` json
437440
{
438441
"datacenter":
439442
{
@@ -449,14 +452,14 @@ As with executable facts, structured data files can set multiple facts at once.
449452
}
450453
```
451454

452-
#### Structured data facts on Windows
455+
#### Structured data based external facts on Windows
453456

454457
All of the above types are supported on Windows with the following caveats:
455458

456459
- The line endings can be either `LF` or `CRLF`.
457460
- The file encoding must be either `ANSI` or `UTF8 without BOM` (Byte Order Mark).
458461

459-
### Troubleshooting
462+
### Troubleshooting external facts
460463

461464
If your external fact is not appearing in OpenFact's output, running
462465
OpenFact in debug mode should give you a meaningful reason and tell you which file is causing the problem:
@@ -489,7 +492,7 @@ found in the `stdlib` module.
489492

490493
### Drawbacks
491494

492-
While external facts provide a mostly-equal way to create variables for Puppet, they have a few drawbacks:
495+
While external facts provide a mostly-equal way to create variables for OpenVox, they have a few drawbacks:
493496

494497
- An external fact cannot internally reference another fact. However, due to parse order, you can reference an external fact from a Ruby fact.
495498
- External executable facts are forked instead of executed within the same process.

docs/_openfact_5x/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ title: "Documentation index"
55

66
OpenFact is OpenVox's cross-platform system profiling library. It discovers and reports per-node facts, which are available in your OpenVox manifests as variables.
77

8-
* [The list of core facts](./core_facts.html) lists and describes every built-in fact that ships with OpenFact.
8+
* [The OpenFact release notes](./release_notes.html) document OpenFact's history.
9+
* [The CLI](./cli.html) lists and describes the command line interface usage and options for OpenFact (auto-generated).
10+
* [The list of core facts](./core_facts.html) lists and describes every built-in fact that ships with OpenFact (auto-generated).
911
* [The custom fact reference](./fact_overview.html) serves as an example-driven primer and quick reference for fact authors.
1012
* [The custom facts walkthrough](./custom_facts.html) explains in detail how to write and distribute your own custom or external facts.
11-
* [The OpenFact release notes](./release_notes.html) document OpenFact's history.
13+
* [The configuration file options](./configuring_openfact.html) explains in detail how to configure the behavior of OpenFact.

0 commit comments

Comments
 (0)