官术网_书友最值得收藏!

Custom facts

Custom facts are a client-side technology for extracting arbitrary information from the node during the execution of the agent run, and they may be utilized in Puppet manifests or templates, along with any other distributed facts. Facts are executed on the Puppet agent.

The best way to create and distribute a new custom fact is to place it in a module, in the facter subdirectory of the lib directory, and it will then be distributed to the agent machine via pluginsync.

This documentation page at https://puppet.com/docs/puppet/5.3/plugins_in_modules.html#adding-plug-ins-to-a-module shows you exactly where in a module to place your code, and the section at https://puppet.com/docs/puppet/5.3/plugins_in_modules.html#installing-plug-ins, in the same documentation, shows the technical details for pluginsync.

The following diagram illustrates the pluginsync process that precedes a normal catalog request. Usually, a GET method is called on the Puppet server using the FQDN, which then initiates the pluginsync process, and the appropriate facts, types, and providers are distributed back to the agent:

You can review the exact details for all the HTTPS communication between the Puppet agent and Puppet Server at https://puppet.com/docs/puppet/5.3/subsystem_agent_master_comm.html.

Most of the time, I have found that a fact is generally just an execution of an arbitrary command-line expression, and that is a good way to think generally about facts: they effectively consist of a Ruby wrapper, usually around a command-line expression that makes itself available to the Puppet ecosystem via Facter.

The following code would be a good snippet to use as a template for further development:

# <modulepath>/lib/facter/mycustomfact.rb
Facter.add(:mycustomfact) do
confine :kernel => "Linux"
...
myvar = Facter::Core::Execution.exec("foo")
...
end

Do make sure that you confine your fact appropriately. There's nothing worse than when you introduce a new operating system to your infrastructure only to find that you are now executing failing facts because they don't use a certain command syntax. Or, what if we suddenly introduce a handful of Windows nodes, only to find that Windows doesn't, of course, understand most Linux commands?

Bear this in mind during your authoring of custom facts.

主站蜘蛛池模板: 康定县| 武邑县| 普安县| 周宁县| 皮山县| 揭东县| 凉山| 延津县| 都昌县| 华宁县| 哈尔滨市| 广平县| 沈丘县| 苏尼特右旗| 平邑县| 九寨沟县| 浦城县| 峨眉山市| 玉溪市| 太谷县| 陈巴尔虎旗| 洛宁县| 信丰县| 中牟县| 邹城市| 古丈县| 方城县| 绍兴市| 呼和浩特市| 平邑县| 诸暨市| 行唐县| 洮南市| 青海省| 明星| 镇坪县| 淄博市| 五原县| 绥江县| 额济纳旗| 冕宁县|