| I did a think-through of this and came up with the following framing, which I think describes how we have implemented this functionality today. Adding a Fact There are three primary ways to add facts to Facter.
- Via the Ruby API's Facter.add() method
- Via a text-emitting external fact
- Via a structured-object emitting external fact
For all three methods, the definition spec is the same. Input: A dot-notation insertion spec indicating where in the Fact tree the new value should appear. Output: The value which should appear at the designated insertion point. Examples Each of the following examples results in the following Fact tree.
{ |
"tier": "production", |
"cmdb" { |
"owner": "Jaime", |
"raci": { |
"responsible": "Jaime", |
"informed": "Logan" |
} |
} |
}
|
Ruby API One insertion per call.
Facter.add("tier") do |
"production" |
end |
|
Facter.add("cmdb.owner") do |
"Jaime" |
end |
|
Facter.add("cmdb.raci") do |
{ "responsible" => "Jaime", "informed" => "Logan" } |
end
|
Text-emitting external fact Text-emitting external facts can only set scalar values at given insertion points, since text does not have a clearly defined way to set arrays or objects. If object structure is required, multiple text insertions can be used together.
tier=production |
cmdb.owner=Jaime |
cmdb.raci.responsible=Jaime |
cmdb.raci.informed=Logan
|
Structure-emitting external fact Multiple insertions allowed in the same output. This example shows using multiple insertions to build cmdb; it would also be possible to build the entirety of cmdb with one insertion. Note however that doing so would potentially prevent other facts from contributing subkeys underneath cmdb.
{ |
"tier": "production", |
"cmdb.owner": "Jaime", |
"cmdb.raci": { |
"responsible": "Jaime", |
"informed": "Logan" |
} |
}
|
The JSON Schema that structured external facts should emit is roughly
{ |
"$schema": "https://json-schema.org/draft/2020-12/schema", |
|
"title": "External Facts", |
"description": "One or more external facts to insert into the Facter tree", |
"type": "object", |
|
"patternProperties": { |
"^.+$": { |
"title": "Fact insertion spec", |
"description": "dot-notation insertion spec for a new fact, with value to insert", |
"type": ["string", "integer", "array,", "object", "null"] |
} |
} |
}
|
|