Adding the custom facts
We may also need custom facts. For example, when dealing with users, it is important to know the Windows users and make changes accordingly. We will start with a simple example that shows how to add a custom fact.
This example custom fact is a simple one. We will create a fact named firstfact
and make its value Hello World!
. We can add custom facts by modules. In a module structure, it adds the facts under the lib/facter
folder. To remember where we put our custom facts, we will create a module named common
and put all our facts in this folder. The name of the module is not important here and you can give it any name. For now, we will just use common
. Here is the module structure:
We will put our custom fact definitions under the facter
folder and the files must have the .rb
extension. The name of the file is not important. All the .rb
files will be processed.
Now, let's continue with the code details of defining a fact:
Facter.add("factname") do setcode do "factvalue...