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

  • Mastering Puppet 5
  • Ryan Russell Yates Jason Southgate
  • 340字
  • 2021-07-16 17:46:14

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.

主站蜘蛛池模板: 搜索| 额济纳旗| 夏津县| 花垣县| 安龙县| 偃师市| 布尔津县| 萨迦县| 长岛县| 克拉玛依市| 波密县| 集安市| 西昌市| 黄石市| 汉阴县| 宝清县| 昭觉县| 平利县| 泰安市| 沾益县| 昂仁县| 崇仁县| 仁化县| 仁寿县| 澄城县| 黄冈市| 长宁县| 西宁市| 前郭尔| 沁阳市| 湘阴县| 民丰县| 离岛区| 安多县| 元朗区| 五指山市| 惠来县| 江川县| 钦州市| 高青县| 盐城市|