facterdb
A Gem that contains a lot of facts for a lot of Operating Systems.
With facterdb 2 legacy facts are deprecated and will be removed in facterdb 3
Some facts were declared legacy a long time ago: Core facts documentation
With Puppet 8 they are disabled by default. With the release of facterdb 3 we will also remove the legacy facts from our factsets.
Usage
CLI
facterdb 'facterversion=/^2.4\./ and (operatingsystem=Debian and operatingsystemrelease>=7 or operatingsystem=RedHat and operatingsystemrelease=/^7/)'
Will return a JSON containing the facts for Debian 7, Debian 8 and RedHat 7 generated by Facter 2.4.
Ruby
require 'facterdb'
FacterDB::get_facts()
Returns an Array of Hash containing the whole facts database.
Filtering by Facter version and fact values
With an Array filter
require 'facterdb'
FacterDB.get_facts([{:osfamily => 'Debian'}])
With an Hash filter
require 'facterdb'
FacterDB.get_facts({:osfamily => 'Debian'})
With a String filter
require 'facterdb'
FacterDB::get_facts('osfamily=Debian')
Included Factsets
Starting with version 1.28.0 (May 2024), check RubyDoc for Factsets included in each released gem.
Check the Voxpupuli website for Factsets included in the master
branch.
Add new Operating System support
There is Vagrantfile
to automagically populate facts
for all supported operating systems by spawning a new VM and launches a provisioning scripts.
Details of how to generate facts for each operating system are here.
Supplying custom external facts
The default facts are great for many things but there will be times when you need to have facterdb search custom
fact sets that only make sense in your environment or might contain sensitive information.
This can be useful when combined with rspec_puppet_facts or the puppet-debugger which both use this gem.
To supply external facts to facterdb just set the FACTERDB_SEARCH_PATHS
environment variable with one or more
paths to your facts. Do this any time facterdb is used directly or indirectly.
When separating paths please use the default path separator character supported by your OS.
- Unix/Linux/OSX =
:
- Windows =
;
Each fact set you create must meet the following requirements:
- A JSON serialized file containing a single Hash of all the facts.
- The facts file must end in
.facts
- Must be placed inside some directory. You can organize this directory however you like.
Facterdb is smart enough the search your supplied directories for files ending with '.facts'. You can even supply
multiple directories.
Example:
FACTERDB_SEARCH_PATHS="/var/opt/lib/custom_facts"
or
FACTERDB_SEARCH_PATHS="/var/opt/lib/custom_facts:/tmp/custom_facts:/home/user1/custom_facts"
We still highly encourage you to create pull requests with new fact sets over of using external facts.
You can create these files via many methods.
puppet facts | jq '.values' > /tmp/custom_facts/datacenter_a/2.4/os_x.facts
# must have jq command- Via puppetdb queries
- hand crafted
Additionally you can skip the default FacterDB facts completely by setting the environment variable FACTERDB_SKIP_DEFAULTDB
.
This will instruct facterdb to not look at its built-in facts which can be useful should you need to completely replace which facts are used.
Setting the variable FACTERDB_SKIP_DEFAULTDB
to anything will disable the internal facts used by facterdb. You would most likely use this in combination
with the FACTERDB_SEARCH_PATHS
environment variable.
Example:
FACTERDB_SEARCH_PATHS="/var/opt/lib/custom_facts:/tmp/custom_facts:/home/user1/custom_facts"
FACTERDB_SKIP_DEFAULTDB='yes'
Debugging fact sets
By setting the environment variable FACTERDB_INJECT_SOURCE
the following facts are injected into all fact sets:
_facterdb_path
: The base name of the file used to load this fact set e.g. centos-5-i386.facts
_facterdb_filename
: The full path of the file used to load this fact set e.g. /project/facter-db/centos-5-i386.facts
{
"_facterdb_path": "centos-5-i386.facts",
"_facterdb_filename": "/project/facter-db/centos-5-i386.facts",
"aio_agent_version": "1.8.3",
"architecture": "i386",
"augeas": {
"version": "1.4.0"
},
"augeasversion": "1.4.0",
"bios_release_date": "07/30/2013",
"bios_vendor": "Phoenix Technologies LTD",
"bios_version": "6.00",
"blockdevice_fd0_size": 4096,
"blockdevice_hdc_size": 4294965248,
"blockdevice_sda_model": "Virtual disk",
...
To set the environment variable use;
bash> FACTERDB_INJECT_SOURCE='true'
or on Windows
powershell> $ENV:FACTERDB_INJECT_SOURCE = 'true'
Contributing
Please submit issues at https://github.com/voxpupuli/facterdb/issues or PRs in the same repository.
Release process
- Update the version in
lib/facterdb/version.rb
- Run
rake changelog
- Commit and PR the results.
Transfer Notice
This plugin was originally authored by Camptocamp.
The maintainer preferred that Puppet Community take ownership of the module for future improvement and maintenance.
Existing pull requests and issues were transferred over, please fork and continue to contribute here instead of Camptocamp.
Previously: https://github.com/camptocamp/facterdb