You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- add missing facts-group in facter config
- switch examples from legacy to structured facts
- add information on writing facts on windows
- timeout der fact
- hint on Facter::Execution.exec deprecation
- add information on logging
Signed-off-by: Martin Alfke <ma@betadots.de>
Copy file name to clipboardExpand all lines: docs/_openfact_5x/configuring_openfact.md
+32-3Lines changed: 32 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@ toc_levels: 1
4
4
title: "Configuring OpenFact with facter.conf"
5
5
---
6
6
7
-
The `facter.conf` file is a configuration file that allows you to cache and block fact groups, and manage how OpenFact interacts with your system. There are three sections: `facts`, `global`and `cli`.
7
+
The `facter.conf` file is a configuration file that allows you to cache and block fact groups, and manage how OpenFact interacts with your system. There are three sections: `facts`, `global`, `cli`and `facts-group`.
8
8
All sections are optional and can be listed in any order within the file.
9
9
10
10
When you run OpenFact from the Ruby API, only the `facts` section and limited `global` settings are loaded.
11
11
12
12
Example facter.conf file:
13
13
14
-
~~~yaml
14
+
~~~hocon
15
15
facts : {
16
16
blocklist : [ "file system", "EC2" ],
17
17
ttls : [
@@ -32,6 +32,9 @@ cli : {
32
32
verbose : false,
33
33
log-level : "warn"
34
34
}
35
+
fact-groups : {
36
+
custom-group-name : ["os.name", "networking.ip"],
37
+
}
35
38
~~~
36
39
37
40
## Location
@@ -79,14 +82,29 @@ file system
79
82
80
83
If you want to block any of these groups, add the group name to the `facts` section of `facter.conf`, with the `blocklist` setting.
81
84
82
-
~~~yaml
85
+
~~~hocon
83
86
facts : {
84
87
blocklist : [ "file system" ],
85
88
}
86
89
~~~
87
90
88
91
Here, the "file system" group has been added, so the `mountpoints`, `filesystems`, and `partitions` facts will all be prevented from loading.
89
92
93
+
Within the `blocklist` and `ttls` settings, one can specify fact names:
94
+
95
+
~~~hocon
96
+
facts : {
97
+
blocklist : [ "disks", "memory.swap" ],
98
+
}
99
+
~~~
100
+
101
+
~~~hocon
102
+
ttls : [
103
+
{ "mountpoints" : 30 days },
104
+
{ "memory.swap" : 6 hours },
105
+
]
106
+
~~~~
107
+
90
108
### `global`
91
109
92
110
The `global` section of `facter.conf` contains settings to control how OpenFact interacts with its external elements on your system.
@@ -111,3 +129,14 @@ The `cli` section of `facter.conf` contains settings that affect OpenFact’s co
111
129
| `trace` | If true, OpenFact prints stacktraces from errors arising in your custom facts. | `false` |
112
130
| `verbose` | If true, OpenFact outputs its most detailed messages. | `false` |
113
131
| `log-level` | Sets the minimum level of message severity that gets logged. Valid options: “none”, “fatal”, “error”, “warn”, “info”, “debug”, “trace”. | “warn” |
132
+
133
+
### `facts-groups`
134
+
135
+
If you have a need to define your own group of facts beacuse you want to manage a larger set of facts within `blocklist` or `ttls` you can make use of the `facts-groups` setting.
136
+
Please note that you can not specify external facts here. Structured facts can be provided using the dot notation.
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.
12
14
@@ -99,7 +101,7 @@ OpenVox gets information about a system from OpenFact, and the most simple way f
99
101
get that information is by executing shell commands. You can then parse and manipulate the
100
102
output from those commands using standard Ruby code.
101
103
102
-
> **Note:** However, it is important to also ceck if any of the OpenVox agent bundled Ruby Libraries can be used.
104
+
> **Note:** However, it is important to also check if any of the OpenVox agent bundled Ruby Libraries can be used.
103
105
104
106
The OpenFact API gives you a few ways to
105
107
execute shell commands:
@@ -134,13 +136,13 @@ To get the output of `uname --hardware-platform` to single out a specific type o
134
136
135
137
## Accessing other facts
136
138
137
-
You can write a custom fact that uses other facts by accessing `Facter.value(:somefact)`.
139
+
You can write a custom fact that uses other facts by accessing `Facter.value(:somefact)`.When accessing parts of a structured fact, one must append the key name:`Facter.value(:os)['family']`.
138
140
If the fact fails to resolve or is not present, OpenFact returns `nil`.
139
141
140
142
Forexample:
141
143
142
144
``` ruby
143
-
Facter.add(:osfamily) do
145
+
Facter.add(:my_osfamily) do
144
146
setcode do
145
147
distid = Facter.value(:os)['family']
146
148
case distid
@@ -163,6 +165,7 @@ Facts have a few properties that you can use to customize how they are evaluated
163
165
164
166
One of the more commonly used properties is the `confine` statement, which
165
167
restricts the fact to only run on systems that matches another given fact.
168
+
However, this should be done cautiously to avoid introducing cyclic dependencies between facts.
166
169
167
170
An example of the confine statement would be something like the following:
168
171
@@ -183,7 +186,37 @@ available on the given system. Since this is only available on Linux systems,
183
186
we use the `confine` statement to ensure that this fact isn't needlessly run on
184
187
systems that don't support this type of enumeration.
185
188
186
-
>**Note:**More information on other ways to confine. e.g. files present can be found a the [Facts overview]
189
+
In our next example the application has different config paths for different OS.
The example retrieves the os fact and uses the family key to compare the OS, then applies logic to determine which application config path to check for.
218
+
219
+
>**Note:**More information on other ways to confine can be found in the [Facts overview]
187
220
188
221
### Custom facts precedence
189
222
@@ -237,7 +270,21 @@ end
237
270
### Custom facts execution timeouts
238
271
239
272
Although this version of OpenFact does not support overall timeouts on resolutions, you can pass a timeout
240
-
to `Facter::Core::Execution#execute`:
273
+
to `Facter::Core::Execution#execute` or specify the timeout per fact.
For example, if an application returns its configuration via /opt/app/bin/app config and this commands is sometimes running very long, you can set a timeout:
> Please note that Facter::Core::Execution::exec has been deprecated in favor of Facter::Core::Execution::execute. This is important when migrating from older versions of Facter.
317
+
318
+
### Logging
319
+
320
+
It's often useful to include logging within custom facts to help with troubleshooting and development. You can log messages using Puppet's built-in logging mechanism:
Logging levels include `debug`, `info`, `warn`, `error`, and `fatal`.
332
+
255
333
## Structured custom facts
256
334
257
335
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.
@@ -304,6 +382,30 @@ If the `chunk` blocks all return arrays or hashes, you can omit the `aggregate`
304
382
305
383
For more examples of aggregate resolutions, see the [aggregate resolutions](./fact_overview.html#writing-facts-with-aggregate-resolutions) section of the [Fact overview] page.
306
384
385
+
## Windows Facts
386
+
387
+
Windows-based systems support custom facts just like Linux or other Unix-like systems.
388
+
The main difference is that many Windows-specific tasks (such as checking installed software or reading from the registry) may require platform-specific Ruby code.
389
+
390
+
Within the Facter::Core::Execution.execute usually powershell commands are used.
391
+
392
+
Here's an example of a Windows custom fact that retrieves the version of Internet Explorer:
Copy file name to clipboardExpand all lines: docs/_openfact_5x/fact_overview.md
+51-8Lines changed: 51 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ Simple facts are typically made up of the following parts:
79
79
* Can take either a string or a block.
80
80
* If given a string, OpenFact executes it as a shell command. If the command succeeds, the output of the command is the value of the fact. If the command fails, the next suitable resolution is evaluated.
81
81
* If given a block, the block's return value is the value of the fact unless the block returns `nil`. If `nil` is returned, the next suitable resolution is evalutated.
82
-
* Can execute shell commands within a `setcode` block, using the `Facter::Core::Execution.exec` function.
82
+
* Can execute shell commands within a `setcode` block, using the `Facter::Core::Execution.execute` function.
83
83
* If multiple `setcode` statements are evaluated for a single resolution, only the last `setcode` block is used.
84
84
85
85
## Writing structured facts
@@ -92,10 +92,9 @@ Structured facts can have [simple](#main-components-of-simple-resolutions) or [a
92
92
```ruby
93
93
Facter.add(:interfaces_array) do
94
94
setcode do
95
-
interfaces =Facter.value(:interfaces)
96
-
# the 'interfaces' fact returns a single comma-delimited string, e.g., "lo0,eth0,eth1"
97
-
# this splits the value into an array of interface names
# cert extensions differs if we run via agent (numeric) or via facter (names)
146
+
# in either way we want to remove pp_preshared_key from the list
147
+
cert.extensions.each do |extension|
148
+
case extension.oid.to_s
149
+
when%r{^1\.3\.6\.1\.4\.1\.34380\.1\.1}
150
+
short_name = oids[extension.oid]
151
+
value = extension.value[2..-1]
152
+
extension_hash[short_name] = value unless short_name =='pp_preshared_key'
153
+
when%r{^pp_}
154
+
short_name = extension.oid
155
+
value = extension.value[2..-1]
156
+
extension_hash[short_name] = value unless short_name =='pp_preshared_key'
157
+
end
158
+
end
159
+
160
+
extension_hash
161
+
end
162
+
end
163
+
```
164
+
122
165
## Writing facts with aggregate resolutions
123
166
124
167
Aggregate resolutions allow you to split up the resolution of a fact into separate chunks.By default, OpenFact merges hashes with hashes or arrays with arrays, resulting in a [structured fact](#writing-structured-facts).
@@ -212,11 +255,11 @@ The fact's output is organized by network interface into hashes, each containing
212
255
```ruby
213
256
Facter.add(:total_free_memory_mb, :type => :aggregate) do
Please check the [GitHub OpenFact release page](https://github.com/OpenVoxProject/openfact/releases/tag/5.6.0) for details on new features or bug fixes
20
-
.
19
+
Please check the [GitHub OpenFact release page](https://github.com/OpenVoxProject/openfact/releases/tag/5.6.0) for details on new features or bug fixes.
0 commit comments