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

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.

主站蜘蛛池模板: 通化县| 瑞丽市| 光泽县| 清原| 新民市| 石狮市| 阳江市| 黄陵县| 乃东县| 互助| 大同市| 永济市| 临城县| 邢台市| 新疆| 弋阳县| 申扎县| 武定县| 株洲市| 平和县| 曲沃县| 通州市| 澳门| 台安县| 邓州市| 赤峰市| 两当县| 年辖:市辖区| 潼关县| 伽师县| 连城县| 绥江县| 宁国市| 青铜峡市| 浦北县| 林西县| 郸城县| 泽普县| 拉孜县| 玉田县| 新昌县|