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

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.

主站蜘蛛池模板: 吉安市| 麦盖提县| 芜湖县| 崇州市| 峨眉山市| 南木林县| 麻栗坡县| 江陵县| 临清市| 临沂市| 孝义市| 高清| 攀枝花市| 厦门市| 昌平区| 东兰县| 建湖县| 家居| 万载县| 清镇市| 诸暨市| 百色市| 历史| 成武县| 黄龙县| 常熟市| 东兴市| 安西县| 天等县| 甘肃省| 新巴尔虎右旗| 裕民县| 霍林郭勒市| 山西省| 慈溪市| 柘荣县| 卢氏县| 绍兴县| 临泉县| 宁海县| 页游|